PowerShell 字符串匹配和管道字符

编程入门 行业动态 更新时间:2024-10-28 21:18:07
本文介绍了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 字符串匹配和管道字符

本文发布于:2023-05-30 15:30:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/371038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   管道   字符   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!