开发者

Why is this regex finding slashes?

[^A-Za-z0-9(\\)@% \"]

I want this regex to find everything except all those characters in there? 开发者_如何学编程it works for most but it's finding slashes.


you need to escape the slash for it to be matched ("[^A-Za-z0-9(\\)@% \"]")

how is this defined in the code? as a string literal? If not you might not be escaping the escapes correctly. Try with an @ at the front, as the regex as is seems to work ok for me and not match the '\' character.

I think you are doing this

string pattern = "[^A-Za-z0-9(\\)@% \"]"

Try like so:

string pattern = @"[^A-Za-z0-9(\\)@% \"]"

you migth find this useful if that is the issue


Because the \ is a special character an needs to be escaped: \\

"[^A-Za-z0-9(\\\\)@% \"]"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜