MultiRegExp class
class MultiRegExp implements RegExp {
Iterable<RegExp> regExps;
MultiRegExp(): this.regExps = new List();
MultiRegExp.fromIterable(Iterable<RegExp> this.regExps);
Iterable<Match> allMatches(String input) {
return new MultiRegExpIterable.fromString(this, input);
}
Iterable<Match> allMatchesFromStringContainer(StringContainer stringContainer) {
return new MultiRegExpIterable(this, stringContainer);
}
Match firstMatch(String input) {
//print('--- MultiRegExp: firstMatch "'+input+'"---');
Match found = null, m;
for (RegExp regExp in regExps) {
m = regExp.firstMatch(input);
//print('RegExp= '+regExp.pattern+'; match= '+(m == null ? 'null' : m[0]));
if (m != null && (found == null || m.start < found.start)) {
found = m;
}
}
//print('--- MultiRegExp: firstMatch END ---');
return found;
}
bool hasMatch(String input) {
for (RegExp regExp in this.regExps) {
if (regExp.hasMatch(input)) {
return true;
}
}
return false;
}
bool get isCaseSensitive => throw new UnsupportedError('MutliRegExp cannot support isCaseSensitive get');
bool get isMultiLine => throw new UnsupportedError('MutliRegExp cannot support isMultiLine get');
Match matchAsPrefix(String string, [int start = 0]) {
Match found = null, m;
for (RegExp regExp in this.regExps) {
m = regExp.matchAsPrefix(string,start);
if (m != null && (found == null || m.start < found.start)) {
found = m;
}
}
return found;
}
String get pattern => throw new UnsupportedError('MutliRegExp cannot support pattern get');
String stringMatch(String input) {
throw new UnsupportedError('MutliRegExp cannot support stringMatch');
}
}
Implements
RegExp
Constructors
new MultiRegExp() #
Constructs a regular expression.
Throws a FormatException if source is not valid regular
expression syntax.
MultiRegExp(): this.regExps = new List();
new MultiRegExp.fromIterable(Iterable<RegExp> regExps) #
MultiRegExp.fromIterable(Iterable<RegExp> this.regExps);
Properties
final bool isCaseSensitive #
Whether this regular expression is case sensitive.
If the regular expression is not case sensitive, it will match an input letter with a pattern letter even if the two letters are different case versions of the same letter.
bool get isCaseSensitive => throw new UnsupportedError('MutliRegExp cannot support isCaseSensitive get');
final bool isMultiLine #
Whether this regular expression matches multiple lines.
If the regexp does match multiple lines, the "^" and "$" characters match the beginning and end of lines. If not, the character match the beginning and end of the input.
bool get isMultiLine => throw new UnsupportedError('MutliRegExp cannot support isMultiLine get');
final String pattern #
The pattern of this regular expression.
String get pattern => throw new UnsupportedError('MutliRegExp cannot support pattern get');
Iterable<RegExp> regExps #
Iterable<RegExp> regExps
Methods
Iterable<Match> allMatches(String input) #
Returns an iterable of the matches of the regular expression on input.
Iterable<Match> allMatches(String input) {
return new MultiRegExpIterable.fromString(this, input);
}
Iterable<Match> allMatchesFromStringContainer(StringContainer stringContainer) #
Iterable<Match> allMatchesFromStringContainer(StringContainer stringContainer) {
return new MultiRegExpIterable(this, stringContainer);
}
Match firstMatch(String input) #
Searches for the first match of the regular expression
in the string
input. Returns null if there is no match.
Match firstMatch(String input) {
//print('--- MultiRegExp: firstMatch "'+input+'"---');
Match found = null, m;
for (RegExp regExp in regExps) {
m = regExp.firstMatch(input);
//print('RegExp= '+regExp.pattern+'; match= '+(m == null ? 'null' : m[0]));
if (m != null && (found == null || m.start < found.start)) {
found = m;
}
}
//print('--- MultiRegExp: firstMatch END ---');
return found;
}
bool hasMatch(String input) #
Returns whether the regular expression has a match in the string input.
bool hasMatch(String input) {
for (RegExp regExp in this.regExps) {
if (regExp.hasMatch(input)) {
return true;
}
}
return false;
}
Match matchAsPrefix(String string, [int start = 0]) #
Match this pattern against the start of string.
If
start is provided, it must be an integer in the range 0 ..
string.length. In that case, this patten is tested against the
string at the
start position. That is, a match is returned if the
pattern can match a part of the string starting from position
start.
Match matchAsPrefix(String string, [int start = 0]) {
Match found = null, m;
for (RegExp regExp in this.regExps) {
m = regExp.matchAsPrefix(string,start);
if (m != null && (found == null || m.start < found.start)) {
found = m;
}
}
return found;
}
String stringMatch(String input) #
Returns the first substring match of this regular expression in input.
String stringMatch(String input) {
throw new UnsupportedError('MutliRegExp cannot support stringMatch');
}