I have a regular expression which I want to negate, e.g.
/(.{0,4})
which String.matches returns the following
"/1234" true
"/12" true
"/" true
"" false
"1234" false
"/12345" false
Is there a way to negate (using regx only) to the above so that the results are:
"/1234" false
"/12" false
"/" false
"" true
"1234" true
"/12345" true
I'm looking for a general solution that would work for any regx without re-writing the whole regex.
I have looked at the following How to negate the whole regex? using (?! pattern), but that doesn't seem to work for me.
The following regx
(?!/(.{0,4}))
returns the following:
"/1234" false
"/12" false
"/" false
"" true
"1234" false
"/12345" false
which is not what I want. Any help would be appreciated.