Regex to filter list of numbers if it contains 51 in a certain location

Viewed 47

I have a list of numbers between 11 and 14 digits. The first two digits are always 00. I want to filter out any numbers that have "51" in position 4 and 5, e.g. 00*51******.

I created this Regex

^(00[1-9](?=(?![5]))(?=(?![1]))\d{8,11})$

but it is not doing "AND operation" and stops on !5. How should I set this "AND" correctly?

Examples:
0035196916180 - Should NOT match because of 00351
0033749593254 - Should match because there is no 00351
0035741368965 - Should match because there 0035"7" and not 1

1 Answers

Given your description and examples, I think this is what you are looking for

^00\d(?!51)\d{8,11}$

See it working on regex101.com.

Related