正则表达式模式。
正则表达式是一种模式(Pattern),可以用来匹配字符串或字符串的一部分。
Dart正则表达式与JavaScript正则表达式一样,具有相同的语法和语义, 可参见JavaScript正则表达式的规范 http://ecma-international.org/ecma-262/5.1/#sec-15.10
firstMatch是最重要的实现方法,它将一个正则表达式应用到字符串,并返回第一个匹配Match。 在RegExp中,其他所有的方法都能基于该方法构建出来。
使用allMatches查找一个字符串中正则表达式所有的匹配。
RegExp exp = new RegExp(r"(\w+)");
String str = "Parse my string";
Iterable<Match> matches = exp.allMatches(str);
请注意原始字符串(使用r
作为字符串的前缀)的使用。
在上面的例子中,使用原始字符串将字符串中的每个字符视为原义字符。
否则,\
将被视为转义符。
- Implements
Constructors
Properties
- hashCode → int
-
获取对象的哈希值。
read-only, inherited - isCaseSensitive → bool
-
正则表达式是否区分大小写。
read-only - isMultiLine → bool
-
正则表达式是否要匹配多行。 Whether this regular expression matches multiple lines.
read-only - pattern → String
-
创建
RegExp
对象使用的正则表达式源字符串。read-only - runtimeType → Type
-
表示对象的运行时类型。
read-only, inherited
Operators
-
operator ==(
other) → bool -
相等操作符。
inherited
Methods
-
allMatches(
String input, [int start = 0]) → Iterable<Match> -
返回一个可迭代对象,包含对于字符串
input
的所有正则表达式匹配。 -
firstMatch(
String input) → Match -
在字符串
input
中,查找正则表达式的第一个匹配。 如果没有匹配,返回null
。 -
hasMatch(
String input) → bool -
返回在字符串
input
中,正则表达式是否有匹配。 -
matchAsPrefix(
String string, [int start = 0]) → Match -
针对开始的字符串匹配模式。
inherited -
noSuchMethod(
Invocation invocation) → dynamic -
当一个不存在的函数或成员变量被访问时,该函数被调用。
inherited -
stringMatch(
String input) → String -
返回字符串中
input
,正则表达式匹配到的第一个子字符串。 -
toString(
) → String -
返回一个用来表示对象的字符串。
inherited