【发布时间】:2018-08-31 08:13:05
【问题描述】:
我有一个字符串列表,需要检查每个项目是否包含某个字符串$path,其中该字符串应包含一个unc 路径,而$path 也是一个unc 路径。
例如:
"RW \\test" -match "\\test"
返回True,因为\\test 包含在RW \\test 中。太好了。
那么为什么会返回 False 呢? :
"RW \\test\te" -match "\\test\te"
起初,我认为单个反斜杠可能以某种方式充当转义字符(即使在 PowerShell 中应该是 `)
所以我尝试了
"RW \\test\\te" -match "\\test\\te"
但这也返回False ....
为什么?
【问题讨论】:
-
"RW \\test\\te" -match "\\\\test\\\\te" -
@PetSerAl 感谢您的评论。所以第二个字符串(比较器)需要用 \\? 转义 \s
-
[Regex]::Escape('\\test\\te')
标签: string powershell path escaping