Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You can add negative lookahead like this:

(?!^\\d+$)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top