Powershell - 正则表达式 - 匹配字符类
以下是 Windows PowerShell 中支持的字符类的示例
##Format: \p{name} #Logic: Matches any character in the named character class specified by # {name}. Supported names are Unicode groups and block ranges such # as Ll, Nd, Z, IsGreek, and IsBoxDrawing. "abcd defg" -match "\p{Ll}+" #Format: \P{name} #Logic: Matches text not included in the groups and block ranges specified # in {name}. 1234 -match "\P{Ll}+" #Format: \w #Logic: Matches any word character. Equivalent to the Unicode character # categories [\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]. If ECMAScript- # compliant behavior is specified with the ECMAScript option, \w is # equivalent to [a-zA-Z_0-9]. "abcd defg" -match "\w+" #(this matches abcd) #Format: \W #Logic: Matches any nonword character. Equivalent to the Unicode categories # [^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]. "abcd defg" -match "\W+" #(this matches the space) #Format: \s #Logic: Matches any white-space character. Equivalent to the Unicode # character categories [\f\n\r\t\v\x85\p{Z}]. "abcd defg" -match "\s+" #Format: \S #Logic: Matches any non-white-space character. Equivalent to the Unicode # character categories [^\f\n\r\t\v\x85\p{Z}]. "abcd defg" -match "\S+" #Format: \d #Logic: Matches any decimal digit. Equivalent to \p{Nd} for Unicode and # [0-9] for non-Unicode behavior. 12345 -match "\d+" #Format: \D #Logic: Matches any nondigit. Equivalent to \P{Nd} for Unicode and [^0-9] # for non-Unicode behavior. "abcd" -match "\D+"
以上所有命令的输出均为True。