字母数字和特殊字符的正则表达式 [英] Regex for alphanumeric and special characters

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

问题描述

我需要定义一个接受字母数字和以下特殊字符的正则表达式:@#$​​%&*()-_+][';:?.,!

I need to define a regular expression that accepts Alphanumeric and the following special characters: @#$%&*()-_+][';:?.,!

我想出了:

string pattern = @"[a-zA-Z0-9@#$%&*+\-_(),+':;?.,![]\s\\/]+$";

但这似乎不起作用.有人可以让我知道缺少什么吗?

But this doesn't seem to be working. Can someone please let me know what is missing?

推荐答案

中间的[]需要转义*:

\[\]

您可能还想用 ^ 锚定字符串的开头.

You also probably want to anchor the start of the string with a ^.

* 可能只是 ] 但我喜欢两者都做以保持平衡.

* Probably just the ] but I like to do both for balance.

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

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