0

I have a REGEX checker that is supposed to return true with the following conditions:

It has to begin with either an underscore '_' or a dot '.'

It has to be immediately followed by one or more occurrences of digits numbered 0-9

It can then have letters, both uppercase or lowercase, 0 or more in number

It can then end with an optional '_'

System.out.println(str.matches("^(_|\\.)[0-9]+[a-zA-z]*(_?)$"));

The above code works for every case except of cases where the string ends with several underscores, which should return a false, but strangely returns true. I tried several things but unfortunately haven't been able to make it work.

_08__ for example is returning true when it should be false.

0 Answers0