操作符 | 说明 | 实例 |
---|---|---|
. | 表示任何单个字符 | |
[ ] | 字符集,对单个字符给出范围 | [abc] 表示 a、b、c,[a-z]表示 a-z 的单个字符 |
[^ ] | 非字符集,对单个字符给出排除范围 | [^abc] 表示非a或b或c的单个字符 |
_ | 前一个字符零次或无限次扩展 | abc_ 表示 ab、abc、abcc、abccc 等 |
` | ` | 左右表达式的任意一个 |
$ | 匹配字符串结尾 | abc$ 表示 abc 且在一个字符串结尾 |
( ) | 分组标记内部只能使用 | (abc) 表示 abc,`(abc |
D | 非数字 | |
d | 数字,等价于0-9 | |
S | 可见字符 | |
s | 空白字符 | |
W | 非单词字符 | |
w | 单词字符,等价于[a-z0-9A-Z_] | |
^ | 匹配字符串开头 | ^abc 表示 abc 且在一个字符串的开头 |
{m,n} | 扩展前一个字符 m 到 n 次 | ab{1,2}c 表示 abc、abbc |
{m} | 扩展前一个字符 m 次 | ab{2}c 表示 abbc |
? | 前一个字符 0 次或 1 次扩展 | abc? 表示 ab、abc |