0

I currently and trying to have a regex validate if a string has a 0 followed by either a 7 or 8. On regex101 it shows as valid but then java fails the match. The regex I used is: ^(0[7-8])

What seems to be valid: https://regex101.com/r/cQMh2k/2

But the java code shows to be false:

System.out.println("08863".matches("^(0[7-8])"));
// prints false

I have also tried these variations to no avail:

^(0{1}[7-8])
^(0*[7-8])
^([0][7-8])
Bhagyesh
  • 576
  • 6
  • 21

0 Answers0