PowerShell 字符串匹配和管道字符 [英] PowerShell String Matching and the Pipe Character

查看:76
本文介绍了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 字符串匹配和管道字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆