“不包含四个或更多重复字符”的正则表达式
我对正则表达式的经验有限,我一直在阅读有关否定和否定前瞻等的各种教程和帖子,但似乎没有什么与我的情况完全匹配。
我正在尝试在 ASP.NET MVC3 中创建一个属性以实现密码复杂性。验证的一部分包括最小数量的重复字符。对于当前项目来说,限制是 3,但我想概括一下。
最初,我使用 @"(.)\1{3,}"
来测试 4 个或更多重复字符,然后否定该结果。我现在无法执行此操作,因为我需要创建一个 ModelClientValidationRegexRule
对象,该对象仅适用于积极的结果。因此,否定必须在正则表达式本身内部完成。我尝试使用负向先行的每种方法都失败了,例如@".*(?!(.)\1{3,})"
。
有什么想法吗?
My experience with regular expressions is limited and I've been reading various tutorials and posts on negation and negative lookahead, etc, but nothing seems to quite match my situation.
I'm trying to create an attribute in ASP.NET MVC3
for password complexity. Part of the validation includes a minimum number of repeated characters. For the current project the limit is 3, but I want to generalize it.
Initially, I was using @"(.)\1{3,}"
to test for 4 or more repeated characters and then negating that result. I can't do that now because I need to create a ModelClientValidationRegexRule
object, which will only work with positive results. As such, the negation must be done inside the regex itself. Every way I've tried to use negative lookahead fails, e.g. @".*(?!(.)\1{3,})"
.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(5)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
扭转问题:一个字符后面最多可以跟 3 个相同的字符。然后它后面必须跟着别的东西。最后,整个字符串必须由这样的序列组成。在 Perl 风格中:
Turn the problem around: a character can be followed by at most 3 of the same. Then it must be followed by something else. Finally, the whole string must consist of sequences like this. In the perl flavor: