我需要使用以下标准生成密码正则表达式:
有效密码必须至少包含 8 个字符。它必须至少有一个大写字母、一个小写字母和一个非字母字符。
到目前为止,我创建了这个模式:
((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,50})
但它仍然采用没有非字母字符的字符串。我怎样才能做到这一点?谢谢
你可以试试这个
                                           |->match 8 or more chars
                                         -----
^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^a-zA-Z]).{8,}$
 ------------ ---------- ---------------
      |           |              |->matches further only if there is atleast 1 non alphabetic char
      |           |->matches further only if there is atleast 1 a-z
      |->matches further only if there is atleast 1 A-Z