1

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?

1
  • 1
    Most engines or programs have some kind of 'not' function that is mostly much more effective than regexp that matches everything 'but'. I'd suggest you to look that way first, then use complex things as desc. in answers. Commented Mar 15, 2012 at 17:03

3 Answers 3

1

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}$
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this worked. I don't need the '^' and '$' since I use the RegEx as terminal in a parser generated with TinyPG.
0

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)

Comments

0

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

1 Comment

Id didn't work. I think that would ignore any Hex Number that has the fist digit 7 and the second digit D od E.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.