Dart API Referencedart:coreRegExp

RegExp abstract class

RegExp represents regular expressions.

Dart regular expressions have the same syntax and semantics as JavaScript regular expressions. See http://ecma-international.org/ecma-262/5.1/#sec-15.10 for the specification of JavaScript regular expressions.

firstMatch is the main implementation method that applies a regular expression to a string and returns the first Match. All other methods in RegExp can build on it.

Use allMatches to look for all matches of a regular expression in a string.

The following example finds all matches of a regular expression in a string.

RegExp exp = new RegExp(r"(\w+)");
String str = "Parse my string";
Iterable<Match> matches = exp.allMatches(str);
abstract class RegExp implements Pattern {
 /**
  * Constructs a regular expression. The default implementation of a
  * [RegExp] sets [multiLine] to false and [caseSensitive] to true.
  * Throws a [FormatException] if [pattern] is not a valid regular
  * exression pattern.
  */
 external factory RegExp(String pattern, {bool multiLine: false,
                                          bool caseSensitive: true});

 /**
  * Searches for the first match of the regular expression
  * in the string [str]. Returns `null` if there is no match.
  */
 Match firstMatch(String str);

 /**
  * Returns an iterable on the  matches of the regular
  * expression in [str].
  */
 Iterable<Match> allMatches(String str);

 /**
  * Returns whether the regular expression has a match in the string [str].
  */
 bool hasMatch(String str);

 /**
  * Searches for the first match of the regular expression
  * in the string [str] and returns the matched string.
  */
 String stringMatch(String str);

 /**
  * The pattern of this regular expression.
  */
 String get pattern;

 /**
  * Whether this regular expression matches multiple lines.
  */
 bool get isMultiLine;

 /**
  * Whether this regular expression is case insensitive.
  */
 bool get isCaseSensitive;
}

Subclasses

JSSyntaxRegExp

Implements

Pattern

Constructors

factory RegExp(String pattern, {bool multiLine: false, bool caseSensitive: true}) #

Constructs a regular expression. The default implementation of a RegExp sets multiLine to false and caseSensitive to true. Throws a FormatException if pattern is not a valid regular exression pattern.

external factory RegExp(String pattern, {bool multiLine: false,
                                        bool caseSensitive: true});

Properties

final bool isCaseSensitive #

Whether this regular expression is case insensitive.

bool get isCaseSensitive;

final bool isMultiLine #

Whether this regular expression matches multiple lines.

bool get isMultiLine;

final String pattern #

The pattern of this regular expression.

String get pattern;

Methods

abstract Iterable<Match> allMatches(String str) #

Returns an iterable on the matches of the regular expression in str.

abstract Match firstMatch(String str) #

Searches for the first match of the regular expression in the string str. Returns null if there is no match.

abstract bool hasMatch(String str) #

Returns whether the regular expression has a match in the string str.

abstract String stringMatch(String str) #

Searches for the first match of the regular expression in the string str and returns the matched string.