W3cubDocs

/Dart 2

RegExp class

A regular expression pattern.

Regular expressions are Patterns, and can as such be used to match strings or parts of strings.

Dart regular expressions have the same syntax and semantics as JavaScript regular expressions. See ecma-international.org/ecma-262/9.0/#sec-regexp-regular-expression-objects 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 RegExpMatch. 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<RegExpMatch> matches = exp.allMatches(str);

Note the use of a raw string (a string prefixed with r) in the example above. Use a raw string to treat each character in a string as a literal character.

Implemented types

Constructors

RegExp(String source, { bool multiLine: false, bool caseSensitive: true, @Since("2.4") bool unicode: false, @Since("2.4") bool dotAll: false })
factory
Constructs a regular expression. [...]

Properties

isCaseSensitivebool
read-only
Whether this regular expression is case sensitive. [...]
isDotAllbool
@Since("2.4"), read-only
Whether "." in this regular expression matches line terminators. [...]
isMultiLinebool
read-only
Whether this regular expression matches multiple lines. [...]
isUnicodebool
@Since("2.4"), read-only
Whether this regular expression is in Unicode mode. [...]
patternString
read-only
The source regular expression string used to create this RegExp.
hashCodeint
read-only, inherited
The hash code for this object. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.

Methods

allMatches(String input, [ int start = 0 ]) → Iterable<RegExpMatch>
override
Returns an iterable of the matches of the regular expression on input. [...]
firstMatch(String input) → RegExpMatch
Searches for the first match of the regular expression in the string input. Returns null if there is no match.
hasMatch(String input) → bool
Returns whether the regular expression has a match in the string input.
stringMatch(String input) → String
Returns the first substring match of this regular expression in input.
matchAsPrefix(String string, [ int start = 0 ]) → Match
inherited
Match this pattern against the start of string. [...]
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 ==(dynamic other) → bool
inherited
The equality operator. [...]

Static Methods

escape(String text) → String
Returns a regular expression that matches text. [...]

© 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/RegExp-class.html