woodtluk
woodtluk

Reputation: 963

Exclude a pattern in RegEx

I want a RegEx to match any Hex number but 7E and 7D.

To match any Hex number I use [0-9A-F]{2}. How can I now exclude the unwandted numbers?

Upvotes: 1

Views: 222

Answers (3)

Ahmad Mageed
Ahmad Mageed

Reputation: 96477

You could use a negative look-ahead that would fail on 7E or 7D. The following pattern uses ^ and $ to match the entire string, not a partial match within a string.

^(?!7[ED])[0-9A-F]{2}$

Upvotes: 1

Alex
Alex

Reputation: 11090

[0-9A-F&&[^7]][0-9A-F&&[^DE]]

Upvotes: 0

Pooria Azimi
Pooria Azimi

Reputation: 8633

You could use something like this:

[0-68-F][0-F] || 7[0-CF]

(the || might not work, depending on where you're using this regex. You didn't specify that in your question)

Upvotes: 0

Related Questions