-1

\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

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.

user8314628
  • 1,952
  • 2
  • 22
  • 46
  • You could try [\d{3}-\d{4}] https://stackoverflow.com/questions/5925738/which-regular-expression-operator-means-dont-match-this-character – greyxit Jul 08 '22 at 16:15
  • Can you share samples of matching strings? How is your string composed? (is it always made up of numbers? Does a dash always occur in it?) – lemon Jul 08 '22 at 16:22
  • @lemon OK, I modify my post with few examples. `xxx-xxxx` should be the correct numbers. I'd to find all other wired data. – user8314628 Jul 08 '22 at 16:29
  • Add `.*` after your regex. Does it work for you? (`^(?!(\d{3}-\d{4})).*`) – lemon Jul 08 '22 at 16:35

1 Answers1

1

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.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880