W3cubDocs

/Dart 2

Match class

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 substrings 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.

Implementers

Constructors

Match()

Properties

endint
read-only
Returns the index in the string after the last character of the match.
groupCountint
read-only
Returns the number of captured groups in the match. [...]
inputString
read-only
The string on which this match was computed.
patternPattern
read-only
The pattern used to search in input.
startint
read-only
Returns the index in the string where the match starts.
hashCodeint
read-only, inherited
The hash code for this object. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.

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. [...]
noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
toString() → String
inherited
Returns a string representation of this object.

Operators

operator [](int group) → String
Returns the string matched by the given group. [...]
operator ==(dynamic other) → bool
inherited
The equality operator. [...]

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-core/Match-class.html