Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有正则表达式:
"(al|sf|sa|sc|nrc|nrc form|doe|doe f|lsi|doe form psd f|doe al f)?[\\s\\-\\.]*[\\d]{3,6}[\\s\\-\\.]*[\\w]{1,4}"
我不希望纯数字字符串(例如“2001”)通过此测试,但“2001”正在通过此正则表达式。为什么?我怎样才能解决这个问题?
?和部分是可选的*,所以正则表达式唯一需要的部分是
?
*
\d{3,6}\w{1,4}
\w包括数字,所以它通过了,因为 2001 是 3\d和 1 \w。
\w
\d
您可以像这样添加负前瞻:
(?!^\\d+$)