【问题标题】:What patterns does PowerShell -like operator support?类似 PowerShell 的运算符支持哪些模式?
【发布时间】:2014-11-06 11:12:46
【问题描述】:

我找不到任何有关 PowerShell -like 运算符语法的参考资料。

comparison operators 上的 Windows PowerShell 参考仅声明:

-喜欢
说明:使用通配符 (*) 进行匹配。

虽然通过实验我发现它也支持?[](设置)。

是否支持任何其他语法?有没有明确的参考 -like 运算符?

【问题讨论】:

    标签: powershell operators pattern-matching wildcard


    【解决方案1】:

    about_Comparison_Operators 的帮助确实声称支持通配符。它无法指定通配符究竟是什么。

    -喜欢 说明:使用通配符 (*) 进行匹配。

    进一步深入了解about_Wildcards 的帮助,我们了解到这些不是你爷爷的通配符:

    Windows PowerShell supports the following wildcard characters.
    
        Wildcard Description        Example  Match             No match
        -------- ------------------ -------- ----------------- --------
        *        Matches zero or    a*       A, ag, Apple      banana
                 more characters
    
        ?        Matches exactly    ?n       an, in, on        ran
                 one character in 
                 the specified 
                 position
    
        [ ]      Matches a range    [a-l]ook book, cook, look  took
                 of characters
    
        [ ]      Matches specified  [bc]ook  book, cook        hook
                 characters
    

    关于通配符帮助的链接在 about_Comparision_Operators 帮助的“另请参阅”部分提到。

    【讨论】:

    • PowerShell globbing 更像 Unix shell 而不是 CMD。
    • 如果要专门匹配*字符,请将其放在括号[*]中。
    猜你喜欢
    • 1970-01-01
    • 2010-12-07
    • 2019-12-02
    • 2023-03-26
    • 2018-06-19
    • 1970-01-01
    • 2013-06-12
    • 2019-07-26
    • 1970-01-01
    相关资源
    最近更新 更多