PowerShell -match vs -like

前端 未结 3 1214
萌比男神i
萌比男神i 2020-12-21 08:41

Reading official docs it\'s obvious that PowerShell -match operator is more powerful than -like (due to regular expressions). Secondly, it seems ~1

3条回答
  •  长情又很酷
    2020-12-21 09:38

    You should prefer -like when your comparator string is a dos-style filename wildcard. If you have a cmdlet that is designed to look like a "standard" windows command line application, then you can expect file name parameters to include dos-style wildcards.

    You might have a grep-like cmdlet that takes a regex and a list of files. I can imagine it being used like this:

    > yourMagicGrepper "^Pa(tt).*rn" *.txt file.*
    

    You would use -match when working with the first parameter, and -like for all other parameters.

    In other words: it depends on your functional requirements.

提交回复
热议问题