C#字符類的正則表達式
字符類匹配一組字符中的任何一個。下表描述了字符類:
字符類 | 描述 | 模式 | 匹配 |
---|---|---|---|
[character_group] | 匹配character_group任何單個字符。默認情況下,匹配是區分大小寫的 | [mn] | "m" 在 "mat"中; "m", "n" 在 "moon" 中 |
[^character_group] | 取反:匹配任何單個字符不在character_group。默認情況下,在character_group的字符是區分大小寫的 | [^aei] | "v", "l" 在 "avail" 中 |
[ first - last ] | 字符範圍:匹配範圍是從第一個到最後任何單個字符 | (w+) | "Name ", "Addr " 在 "Name Addr " 中 |
. | 通配符:匹配任何單個字符,除了 . | a.e | "ave" 在 "have" 中;"ate" 在 "mate" 中 |
p{ name } | 匹配由指定的Unicode通用類彆的任何單個字符或命名塊 name. | p{Lu} | "C", "L" 在 "City Lights" 中 |
P{ name } | Matches any single character that is not in the Unicode general category or named block specified by name. | P{Lu} | "i", "t", "y" in "City" |
w | Matches any word character. | w | "R", "o", "m" and "1" in "Room#1" |
W | Matches any non-word character. | W | "#" in "Room#1" |
s | Matches any white-space character. | ws | "D " in "ID A1.3" |
S | Matches any non-white-space character. | sS | " _" in "int __ctr" |
d | Matches any decimal digit. | d | "4" in "4 = IV" |
D | Matches any character other than a decimal digit. | D | " ", "=", " ", "I", "V" in "4 = IV" |