powershell命令是什么知道字符串是否包含字母a-z,A-Z,0-9,_,。, - 的字符?

时间:2017-12-20 15:49:57

标签: regex powershell conditional-statements

powershell命令是什么知道字符串' / DSA_Global_UNIX / Library / Global / UNIX / Server正常运行时间报告/服务器正常运行时间和补丁合规性报告'包含一个字母,而不是字母a-z,A-Z,0-9,_,。, - ?

1 个答案:

答案 0 :(得分:1)

代码

$str -match '[^\w.-]'

用法

$str = "/DSA_Global_UNIX/Library/Global/UNIX/Server Uptime Report/Server uptime and Patch Compliance report"
$str -match '[^\w.-]'

结果

对于您的字符串,它会返回true,因为它包含/(空格)。

只有来自集合[\w.-]的字符的字符串将返回false,例如:

DSA_Global_UnixLibraryGlobalUNIXServerUptimeReportServeruptimeandPathCompliancereport