What patterns does PowerShell -like operator support?

戏子无情 提交于 2019-12-30 06:06:37

问题


I was not able to find any reference about syntax of the PowerShell -like operator.

Windows PowerShell reference on comparison operators states only:

-Like
Description: Match using the wildcard character (*).

Though by experimenting I've found that it also supports the ? and the [] (set).

Is there any other syntax supported? Is there any definitive reference to the -like operator?


回答1:


The help for about_Comparison_Operators indeed claims wildcard support. It fails to specify what, exactly, a wildcard is.

-Like Description: Match using the wildcard character (*).

Further digging into help about_Wildcards we learn that these aren't your grandpa's 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

The link to wildcard help is mentioned on the See also -section in about_Comparision_Operators help.



来源:https://stackoverflow.com/questions/26778044/what-patterns-does-powershell-like-operator-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!