主要要素
字符
[a-zA-Z] 即 \w
[0-9] 即 \d
[^0-9] 即 \D
\s 即 空白
\S 即 非空白
. 通配符
次数
* 即 {0,}
+ 即 {1,}
? 即 {0,1}
*? +? ?? 懒惰匹配,尽量匹配少
| 或
() 组合
位置限定
^ 首
$ 尾
\b 单词边界
\B 非单词边界
(?<a>xxxx)(yyyy)
替换时:
${a} => $1 => xxxx
$2 => yyyy
(?i:xxxxx)
忽略大小写
Regex
命名空间:using System.Text.RegularExpressions;
Regex.IsMatch | Match | Matches | Replace(s,r)
Match.Groups | Value | Result
1 | using System; |