要求密码的正则表达式,需要一个数字或一个非字母数字字符

我正在寻找一个相当具体的正则表达式,我几乎拥有它但不完全.

我想要一个需要至少5个字符的正则表达式,其中至少有一个字符是数字值或非字母数字字符.

这是我到目前为止:

^(?=.*[\d]|[!@#$%\^*()_\-+=\[{\]};:|\./])(?=.*[a-z]).{5,20}$

所以问题是“或”部分.它将允许非字母数字值,但仍需要至少一个数值.你可以看到我有或运算符“|”在我需要的数字和非字母数字之间,但这似乎不起作用.

任何建议都会很棒.

尝试:
^(?=.*(\d|\W)).{5,20}$

一个简短的解释:

^                         # match the beginning of the input
(?=                       # start positive look ahead
  .*                      #   match any character except line breaks and repeat it zero or more times
  (                       #   start capture group 1
    \d                    #     match a digit: [0-9]
    |                     #     OR
    \W                    #     match a non-word character: [^\w]
  )                       #   end capture group 1
)                         # end positive look ahead
.{5,20}                   # match any character except line breaks and repeat it between 5 and 20 times
$                        # match the end of the input

相关文章

正则替换html代码中img标签的src值在开发富文本信息在移动端...
正则表达式
AWK是一种处理文本文件的语言,是一个强大的文件分析工具。它...
正则表达式是特殊的字符序列,利用事先定义好的特定字符以及...
Python界一名小学生,热心分享编程学习。
收集整理每周优质开发者内容,包括、、等方面。每周五定期发...