为什么这个正则表达式会找到斜杠?
[^A-Za-z0-9(\\)@% \"]
我希望这个正则表达式找到除了其中所有字符之外的所有内容?它适用于大多数人,但它会发现斜线。
[^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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要转义斜杠才能匹配
("[^A-Za-z0-9(\\)@% \"]")
这是如何在代码中定义的?字符串文字?如果不是,您可能无法正确转义。尝试在前面使用@,因为正则表达式对我来说似乎可以正常工作,并且与“\”字符不匹配,
我认为您正在这样做
。所以:
你可能会发现如果这是问题,这很有用
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
Try like so:
you migth find this useful if that is the issue
由于
\
是特殊字符,需要转义:\\
"[^A-Za-z0-9(\\\\)@% \"]"
Because the
\
is a special character an needs to be escaped:\\
"[^A-Za-z0-9(\\\\)@% \"]"