编辑不属于我的正则表达式,不知道如何根据需要调整它
我有一个为我编写的密码正则表达式:
~^[a-z0-9!@#\$%\^&\*\(\)]{8,16}$~i
它应该匹配字母数字字符串和 8-16 个字符的符号。现在我需要删除最小和最大长度要求,因为我需要拆分错误消息以方便用户 - 我尝试只取出 {8,16} 部分,但随后它破坏了它。我该怎么做?提前致谢。
I have a regex that was written for me for passwords:
~^[a-z0-9!@#\$%\^&\*\(\)]{8,16}$~i
It's supposed to match strings of alphanumerics and symbols of 8-16 characters. Now I need to remove the min and max length requirement as I need to split the error messages for user friendliness - I tried to just take out the {8,16} portion but then it breaks it. How would I do this? Thanks ahead of time.
我认为您正在对太长或太短的字符串进行单独检查,并且此正则表达式只是确保不存在无效字符。这应该可以做到:
+
表示一个或多个,*
表示零个或多个;您使用哪一个可能并不重要。我也去掉了一些不必要的反斜杠;这些字符在字符类中没有任何特殊含义(即在方括号内)。
I take it you're doing separate checks for too-long or too-short strings, and this regex is only making sure there are no invalid characters. This should do it:
+
means one or more,*
means zero or more; it probably doesn't matter which one you use.I got rid of some unnecessary backslashes, too; none of those characters has any special meaning in a character class (inside the square brackets, that is).