很明显,这个问题多次被问到如何使用c#来制作正则表达式以满足要求。我需要一个正则表达式..
尝试自己解决这个问题我正在考虑如何逐个搜索这些要求中的每一个,并按照我的方式构建正则表达式。这是正确的做法吗?
我觉得我可能会遗漏一些东西。我正在阅读有关正则表达式以及如何创建复杂表达式的内容。您的反馈非常需要。
感谢。
答案 0 :(得分:2)
我认为你可以使用这样的Regex
:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()])(?!.*userName)(?!.*(.)\1{2,}).{8,}$
说明:
^ // from start
(?=.*[a-z]) // has at least one lower case character
(?=.*[A-Z]) // has at least one upper case character
(?=.*\d) // has at least one digit
(?=.*[!@#$%^&*()]) // has at least one special character
(?!.*userName) // has not userName => set it by a variable
(?!.*(.)\1{2,}) // has not an repeated character more than twice
.{8,} // has a length of 8 and more
$ //to the end