Would like to find out how to validate a string such that first 3 consecutive digits cannot be 8 or 9 consecutively? Example:
88839182 (not valid)
99923213 (not valid)
98188823 (valid)
98939117 (valid)
Tried using s.match("([98]){3}") but it doesn't seem to work, as it takes in 989 for first 3 character too.
You can use following regex for identifying the 3 consecutive 8 or 9 :
Demo
And for matching the numbers that you want you can use a negative look ahead to match numbers that doesn't precede by 3 consecutive 9 or 8:
Demo
Also as a nice suggestion by @Luv2code you can use following regex that will forced your regex engine to match digits: