本文介绍了PowerShell 字符串匹配和管道字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 PowerShell 中匹配包含管道字符的字符串有困难.Match 在以下情况下不应该返回 true:
I am having difficulty matching strings in PowerShell that contain the pipe characters. Match returns true in the following scenario when it shouldn't:
> "Debug|x86" -match "Debug|x128" True我尝试转义匹配参数管道字符,但这不会改变意外结果,例如:
I have tried escaping the match argument pipe character, but this doesn't change the unexpected result, e.g:
> "Debug|x86" -match "Debug`|x128" True 推荐答案这是一个正则表达式,所以需要用反斜杠转义,而不是 PowerShell 的反引号,例如:
It's a regular expression so needs to be escaped with backslash, not PowerShell's backtick, e.g.:
> "Debug|x86" -match "Debug\|x128" False因为它是一个正则表达式,如果管道字符没有被转义,它的计算结果是Debug or x128".
As it is a regular expression, If the pipe character is not escaped, it evaluates to "Debug or x128".
更多推荐
PowerShell 字符串匹配和管道字符
发布评论