The ?
and *
parts are optional, so the only required part of the regex is
\d{3,6}\w{1,4}
\w
includes digits, so it passes because 2001 is 3 \d
and 1 \w
.
문제
I have the regular expression:
"(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}"
I do not want purely numeric strings such as "2001" to pass this test, but "2001" is passing for this regular expression. Why? How can I fix this?
해결책
The ?
and *
parts are optional, so the only required part of the regex is
\d{3,6}\w{1,4}
\w
includes digits, so it passes because 2001 is 3 \d
and 1 \w
.
다른 팁
You can add negative lookahead like this:
(?!^\\d+$)