Match class

A result from searching within a string.

A result from searching within a string.

A Match or an Iterable of Match objects is returned from Pattern matching methods.

The following example finds all matches of a RegExp in a String and iterates through the returned iterable of Match objects.

RegExp exp = new RegExp(r"(\w+)");
String str = "Parse my string";
Iterable<Match> matches = exp.allMatches(str);
for (Match m in matches) {
  String match = m.group(0);
  print(match);
}

The output of the example is:

Parse
my
string

Some patterns, regular expressions in particular, may record subtrings that were part of the matching. These are called groups in the Match object. Some patterns may never have any groups, and their matches always have zero groupCount.

Constructors

Match ( )

Instance Properties

start int
read-only
end int
read-only
groupCount int
read-only
input String
read-only
pattern Pattern
read-only

Instance Methods

group ( int group ) → String
Returns the string matched by the given group.
groups ( List<int> groupIndices ) → List<String>
Returns a list of the groups with the given indices.

Operators

operator [] ( int group ) → String
Returns the string matched by the given group.