特殊字符的正则表达式? [英] Regular Expression for special characters?

查看:107
本文介绍了特殊字符的正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的正则表达式,以避免特殊字符,例如!''',?/ @ etc

解决方案

解决方案1提供正确的想法。此外,你可能想要做一个不同的事情:你可以在输入时过滤掉不需要的字符。在Web应用程序中,这是用JavaScript完成的。​​只有一个细节,经常被遗忘,不要忘记允许字符#8,退格。



至于Regex,你的问题是基本的,所以你最好学习正则表达式。你可以开发和学习正则表达式如果你使用Expresso非常有效: http://www.ultrapico.com/Expresso.htm [ ^ ]。



见还:

http://en.wikipedia.org/wiki/Regular_expression [ ^ ],

http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx [ ^ ]。



-SA


理想情况下,您必须仅允许所需的字符,而不是避免使用特殊字符。然后,将自动禁止所有其他字符。



我建议您通过此链接进行进一步说明,并附带示例:http://stackoverflow.com/questions/756567/regular-expression-for-excluding-special-characters [ ^ ]

what can be the best possible regular expression to avoid special characters e.g !''",?/@ etc

解决方案

Solution 1 provides right idea. Besides, you may want to do a different thing: instead of validation, you could filter out unwanted character while they are entered. In a Web application, this is done in JavaScript. Just one detail, often forgotten, don''t forget to allow "character" #8, backspace.

As to Regex, your problem is one of the basic, so you better need to learn Regex. You can develop and learn Regular Expressions very effectively if you use Expresso: http://www.ultrapico.com/Expresso.htm[^].

See also:
http://en.wikipedia.org/wiki/Regular_expression[^],
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx[^].

—SA


Rather than avoid special characters, ideally you have to allow the required characters only. Then, automatically all other characters will be not allowed.

I would recommend you to go through this link for further explanation with examples: http://stackoverflow.com/questions/756567/regular-expression-for-excluding-special-characters[^]


这篇关于特殊字符的正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆