Match class - dart:core library (original) (raw)

A result from searching within a string.

A Match or an Iterable of Match objects is returned from the Pattern matching methods (Pattern.allMatches and Pattern.matchAsPrefix).

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

final regExp = RegExp(r'(\w+)');
const string = 'Parse my string';
final matches = regExp.allMatches(string);
for (final m in matches) {
  String match = m[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 Matchobject. Some patterns may never have any groups, and their matches always have zero groupCount.

Implementers

Properties

endint

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

no setter

groupCountint

Returns the number of captured groups in the match.

no setter

hashCodeint

The hash code for this object.

no setterinherited

inputString

The string on which this match was computed.

no setter

patternPattern

The pattern used to search in input.

no setter

runtimeTypeType

A representation of the runtime type of the object.

no setterinherited

startint

The index in the string where the match starts.

no setter

Methods

group(int group)→ String?

The string matched by the given group.

groups(List<int> groupIndices)→ List<String?>

A list of the groups with the given indices.

noSuchMethod(Invocation invocation)→ dynamic

Invoked when a nonexistent method or property is accessed.

inherited

toString()→ String

A string representation of this object.

inherited

Operators

operator ==(Object other)→ bool

The equality operator.

inherited

operator [](int group)→ String?

The string matched by the given group.