我正在寻找一个相当具体的正则表达式,我几乎有,但不完全。
我想要一个至少需要5个字符的正则表达式,其中至少有一个字符是数字值或非字母数字字符。
到目前为止,这就是我所拥有的:
^(?=.*[\d]|[!@#$%\^*()_\-+=\[{\]};:|\./])(?=.*[a-z]).{5,20}$所以问题在于“或”部分。它将允许非字母数字值,但仍然需要至少一个数字值.您可以看到,我的要求数字和非字母数字之间有或运算符“\”,但这似乎不起作用。
任何建议都会很好。
发布于 2010-01-04 08:06:08
尝试:
^(?=.*(\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发布于 2010-01-04 05:28:42
也许这对你有用:
^.*[\d\W]+.*$并使用以下代码检查字符串大小:
if(str.len >= 5 && str.len =< 20 && regex.ismatch(str, "^.*[\d\W]+.*$")) { ... }发布于 2010-01-04 05:17:13
像这样怎么样?
^.*?[\d!@#$%\^*()_\-+=\[{\]};:|\./].*$对于长度5,20,请使用正规的strlen函数
https://stackoverflow.com/questions/1997616
复制相似问题