1

I wrote this perl regex in order to get all mac-addresses:

^(?([0-9A-Fa-f]{12}))$

This works fine, but the inverse match (all string without mac-address) doesn't works:

^(?!([0-9A-Fa-f]{12}))$

what is the best way to write this regex?

Community
  • 1
  • 1
Vincenzo
  • 87
  • 2
  • 7

1 Answers1

1

With your original pattern you are starting a conditional (the (?(...) part), but without then/else clause. I am quite sure you didn't want this.

Your second pattern has the problem, that you are checking a condition with your negated lookahead, but you don't match something. So change it to

^(?![0-9A-Fa-f]{12}$).*$

This will match any pattern that is not [0-9A-Fa-f]{12}.

stema
  • 90,351
  • 20
  • 107
  • 135