.net Regex连续两封以上的信件

时间:2012-03-18 17:21:30

标签: .net regex

我正在尝试连续写两封以上的.Net Regex。

aa - fine
Aa - fine
aaa - not allowed
Aaa - not allowed

我是regex的新手,但这是我到目前为止拼凑的内容。

if (Regex.IsMatch(Password, @"/[^A-Za-z]{2}/"))
    return "Password cannot contain 3 consecutive same letters"; 

我不确定这是否接近。

1 个答案:

答案 0 :(得分:6)

你需要删除斜杠(为什么它们在那里?这不是PHP)你可以使用ignore case标志。像:

Regex.Match(pw, @"(?i)(.)\1\1")

与...相同:

Regex.Match(pw, @"(.)\1\1", RegexOptions.IgnoreCase)

由Ilia G评论。

相关问题