正则表达式的表达式的所有​​非字母数字符号 [英] Regex Expressions for all non alphanumeric symbols

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

问题描述

我试图做一个正则表达式为中有至少1个非字母数字符号的字符串



我想使用的代码是

 正则表达式symbolPattern =新的正则表达式([@#$%^&放大器;?!*()_- + = {[]}; :其中;> | ./?]); 



我想只匹配的!@#$%的一种^ &放大器; *()_- + = {[]};:<> | ./?.,但它似乎并不奏效


< DIV CLASS =h2_lin>解决方案

如果要匹配非字母数字符号就用 \W | _

 正则表达式=新的正则表达式(@\W | _); 

这将匹配除0-9什么,A-Z。在 \W 字符类和其他在这里可用信息。




I am trying to make a regular expression for a string that has at least 1 non alphanumeric symbol in it

The code I am trying to use is

Regex symbolPattern = new Regex("?[!@#$%^&*()_-+=[{]};:<>|./?.]");

I'm trying to match only one of !@#$%^&*()_-+=[{]};:<>|./?. but it doesn't seem to be working.

解决方案

If you want to match non-alphanumeric symbols then just use \W|_.

Regex pattern = new Regex(@"\W|_");

This will match anything except 0-9 and a-z. Information on the \W character class and others available here.

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

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