Dart API Referencedart:coreMatch

Match abstract class

Match contains methods to manipulate a regular expression match.

Iterables of Match objects are returned from RegExp 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 = const 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
abstract class Match {
  /**
   * Returns the index in the string where the match starts.
   */
  int start();

  /**
   * Returns the index in the string after the last character of the
   * match.
   */
  int end();

  /**
   * Returns the string matched by the given [group]. If [group] is 0,
   * returns the match of the regular expression.
   */
  String group(int group);
  String operator [](int group);

  /**
   * Returns the strings matched by [groups]. The order in the
   * returned string follows the order in [groups].
   */
  List<String> groups(List<int> groups);

  /**
   * Returns the number of groups in the regular expression.
   */
  int groupCount();

  /**
   * The string on which this matcher was computed.
   */
  String get str;

  /**
   * The pattern to search for in [str].
   */
  Pattern get pattern;
}

Properties

final Pattern pattern #

The pattern to search for in str.

Pattern get pattern;

final String str #

The string on which this matcher was computed.

String get str;

Operators

String operator [](int group) #

String operator [](int group);

Methods

int end() #

Returns the index in the string after the last character of the match.

int end();

String group(int group) #

Returns the string matched by the given group. If group is 0, returns the match of the regular expression.

String group(int group);

int groupCount() #

Returns the number of groups in the regular expression.

int groupCount();

List<String> groups(List<int> groups) #

Returns the strings matched by groups. The order in the returned string follows the order in groups.

List<String> groups(List<int> groups);

int start() #

Returns the index in the string where the match starts.

int start();