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?
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?
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}
.