为什么-split参数的字符串需要两个反斜杠,而-join参数的字符串只需要一个反斜杠?在Powershell中,反引号是转义字符。反斜杠前加一个字符有什么作用?
$path = 'C:\folder\test\unit1\testing\results\report.txt'
$path -split '\\' -notlike '*test*' -join '\'
http://powershell.com/cs/blogs/tips/archive/2014/06/17/fun-with-path-names.aspx
-split
可以接受最多 3 个参数:<delimiter>
、<max-substrings>
、<options>
。因此,在 Powershell <7.0 中,-split '\', -1, 'SimpleMatch'
的意思是在\\
上进行拆分,返回 所有 匹配项(max-substrings 为 0 或更低会返回 PS <7.0 中的所有匹配项),并使用 SimpleMatch 而不是默认的 RegexMatch。参考链接:https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_split?view=powershell-7.3 - Prid