简体   繁体   English

类似于Powershell的操作员困惑

[英]Powershell -like operator confusion

为什么以下Powershell代码给出false而不是true?

"ok" -like "??p*"

Because * is a wildcard/glob and not a regex metacharacter. 因为*是通配符/通配符,而不是正则表达式元字符。

Your pattern ??p* isn't saying "any two characters followed by zero-or-more 'p' characters" it is saying "any two characters followed by a 'p' followed by anything". 您的模式??p*并不是说“任何两个字符后接零个或多个'p'字符”,而是说“任何两个字符后接有'p'后跟任何字符”。

Your wildcard expression expect at least 3 characters with the third character being a p. 您的通配符表达式期望至少包含3个字符,第三个字符为p。 As this is not the case the expression will return false. 由于不是这种情况,表达式将返回false。

See http://ss64.com/ps/syntax-wildcards.html 参见http://ss64.com/ps/syntax-wildcards.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM