问题
I need to search for the amount of backslashes in a string to determine some file path parameters. I have not worked out a way to seach for a backslash without Powershell thinking it is an escapee character.
([regex]::Matches($FilePath, "\" )).count
Or
$a -match "\"
These both come up with an error "Illegal \ at end of pattern"
Thanks!
回答1:
You can escape a backslash with a backslash:
[Regex]::Matches($FilePath, "\\").Count
来源:https://stackoverflow.com/questions/35497077/searching-for-backslash-in-a-string-with-powershell