Searching for backslash in a string with Powershell

吃可爱长大的小学妹 提交于 2020-01-16 00:49:20

问题


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

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