The regular expression you are after will most likely be huge and a nightmare to maintain especially for people who are not that familiar with regular expressions.
(您所追求的正则表达式很可能非常庞大且难以维护,尤其是对于不那么熟悉正则表达式的人。)
I think it would be easier to break your regex down and do it one bit at a time.
(我认为分解您的正则表达式并一次执行一次会更容易。)
It might take a bit more to do, but I am pretty sure that maintaining it and debugging it would be easier. (可能还需要做更多的工作,但是我敢肯定,维护和调试它会更容易。)
This would also allow you to provide more directed error messages to your users (other than just Invalid Password
) which should improve user experience. (这还将使您能够向用户提供更多定向错误消息(不仅仅是Invalid Password
),这将改善用户体验。)
From what I am seeing you are pretty fluent in regex, so I would presume that giving you the regular expressions to do what you need would be futile.
(从我所看到的来看,您在regex方面相当流利,所以我认为为您提供正则表达式来做您需要的事情是徒劳的。)
Seeing your comment, this is how I would go about it:
(看到您的评论,这就是我的处理方式:)
Must be eight characters Long: You do not need a regex for this.
(长度必须为八个字符:为此,您不需要正则表达式。)
Using the .Length
property should be enough. (使用.Length
属性应该足够了。)
Including one uppercase letter: You can use the [AZ]+
regular expression.
(包括一个大写字母:您可以使用[AZ]+
正则表达式。)
If the string contains at least one upper case letter, this regular expression will yield true
. (如果字符串包含至少一个大写字母,则此正则表达式将产生true
。)
One special character: You can use either the \W
which will match any character which is not a letter or a number or else, you can use something like so [!@#]
to specify a custom list of special characters.
(一个特殊字符:可以使用\W
来匹配非字母或数字的任何字符,否则可以使用[!@#]
这样的东西来指定特殊字符的自定义列表。)
Note though that characters such as $
, ^
, (
and )
are special characters in the regular expression language, so they need to be escaped like so: \$
. (请注意,尽管$
, ^
(
和)
类的字符在正则表达式语言中是特殊字符,所以需要像\$
这样进行转义。)
So in short, you might use the \W
. (简而言之,您可以使用\W
)
Alphanumeric characters: Using the \w+
should match any letter and number and underscore.
(字母数字字符:使用\w+
应该匹配任何字母,数字和下划线。)
Take a look at this tutorial for more information.
(查看本教程以获取更多信息。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…