Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex how to match everything that doesn't follow the format with 3 digits followed by a dash then 4 digits?

\d{3}-\d{4}
This one matches something like 123-4567

So I change it to ^(?!(\d{3}-\d{4})). But it doesn’t match anything.

I got a list of phone numbers like

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

123-4567
NOW-4-WAX
12 345 67 89

I would like to match anything except the format xxx-xxxx where x is a digit.

>Solution :

If you add .* to the end of your regex, it should match any line that does not start with a phone number in the 123-4567 format.

Demo on RegExr: ^(?!(\d{3}-\d{4})).*$

It’s worth noting that if you have anything in your input file that is not a phone number at all, this will match those too.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading