.NET的正则表达式连续超过2个字母 [英] .net Regex for more than 2 consecutive letters
本文介绍了.NET的正则表达式连续超过2个字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图写一个.net正则表达式超过2 consecutives字母。
I am attempting to write a .Net Regex for more than 2 consecutives letters.
aa - fine
Aa - fine
aaa - not allowed
Aaa - not allowed
我是新来的正则表达式,但是这是我所拼凑至今。
I am new to regex, but this is what I have pieced together so far.
if (Regex.IsMatch(Password, @"/[^A-Za-z]{2}/"))
return "Password cannot contain 3 consecutive same letters";
我不知道这是否是关闭与否。
I am not sure if this is close or not.
推荐答案
您需要删除的斜线(他们为什么呢?这是不是PHP),你可以用忽略大小写标志。像:
You need to remove the slashes (why are they there? this is not PHP) and you could use the ignore case flag. Like:
Regex.Match(pw, @"(?i)(.)\1\1")
这是一样的:
Which is same as:
Regex.Match(pw, @"(.)\1\1", RegexOptions.IgnoreCase)
由于评论由伊利亚-G。
As commented by Ilia G.
这篇关于.NET的正则表达式连续超过2个字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文