类似 PowerShell 的格式化
我正在尝试测试字符串是否采用两种格式之一:标题(年份)或标题(年份)[Addl]
对于第一个,这有效: if ($name -like "* (*)") ...
对于第二个,这不起作用: if ($name -like "* (*) [*]")...
我知道括号使它认为它是一个正则表达式。如何使其不是正则表达式?
感谢您的帮助!
I am trying to test if a string is in one of two formats: Title (Year) or Title (Year) [Addl]
For the first, this works: if ($name -like "* (*)")...
For the second, this does not work: if ($name -like "* (*) [*]")...
I know the brackets make it think it is a regular expression. How do I make it not a regular expression?
Thanks for your assistance!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于通配符表达式< /a> 在 PowerShell 中,转义字符是反引号
`
:测试这一点的一种方法是使用
[WildcardPattern]::Escape(..)
:如果您想使用以下命令测试模式正则表达式 你会使用
-match
运算符,转义字符将是反斜杠\
:并且,如 briantist 的有用评论指出,您可以使用
[regex]::Escape(..)
转义正则表达式特殊字符:For Wildcard expressions in PowerShell, the escape character is the backtick
`
:One way to test this is using
[WildcardPattern]::Escape(..)
:If you want to test the pattern using regular expressions you would be using the
-match
operator, and the escape character would be the backslash\
:And, as briantist's helpful comment points out, you can use
[regex]::Escape(..)
to escape regex special characters: