[英]How to Write a Regular Expression that allows only letters, numbers and special characters only i the middle never in the end
Need some regular expressions help. 需要一些正则表达式帮助。
So far I have my code working to allow a limited number of special characters. 到目前为止,我的代码正在允许有限数量的特殊字符。 However, I don't know how to get it to only allow them in the middle and never the end.
但是,我不知道如何让它只在中间,而不是在最后。
Can someone help me figure that part out? 有人可以帮我弄清楚那部分吗?
Here is the code I am using in c#: 这是我在C#中使用的代码:
Regex uRLToVal= new Regex("^[A-Za-z0-9-_.+!*]*$");
if (!uRLToVal.IsMatch(this.mainURL))
{
results.AddPropertyError("Your Entry can only contain letters, numbers, underscores, periods, plus, exclamation marks and hypens. Special characters should always be inside numbers or letters. Example: v!v is OK BUT NOT !vv or vv!");
}
new Regex(@"^[A-Za-z0-9]+([-_.+!*]+[A-Za-z0-9]+)*$");
which means : 意思是 :
match must begin with at least one numeric or alpha char: [AZ-z0-9]+
匹配必须以至少一个数字或字母字符开头:
[AZ-z0-9]+
That sequence may be followed by zero or many special chars -_.+!*
followed by at least one numeric or alpha char. 该序列后可以跟零或许多特殊字符
-_.+!*
然后至少跟一个数字或字母字符。 This second combination can happen zero or many times (example : asdf-e*r!asdf
, or a
are valid) 第二个组合可能发生零次或多次(例如:
asdf-e*r!asdf
或a
有效)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.