NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
[0-9]+ any character of: '0' to '9' (1 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of
the string
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
[a-zA-Z0-9]+ any character of: 'a' to 'z', 'A' to 'Z',
'0' to '9' (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
2 回答
试试这个 . 这将确保你至少有一个数字通过
negative looahead
参见演示 .https://regex101.com/r/tX2bH4/43
使用基于前瞻性的正则表达式 .
开头的正面预测
(?=.*?[a-zA-Z])
断言要匹配的字符串必须包含至少一个字母 . 如果是,则仅匹配一个或多个字母或数字 .^
声称我们在开始时$
指的是一行的结尾 .DEMO