Regex to find hex value greater than a specific value

Question:

Hi I am trying to find a regex that would match occurances greater than a particular value.
I am currently using this to match instances greater than 0. I want to get the match only if its greater than 5.which means 0x2, 0x1 and 0x4 wouldnt be matched below

Error.*[1-9|A-F]

Errors : 0x22
Errors : 0x2
Errors : 0x67
Errors : 0xA1
Errors : 0x5
Errors : 0x4
Errors : 0x0 Not matched 
Errors : 0x1

Thanks.

Asked By: Red Gundu

||

Answers:

For the examples, if 0x2, 0x1 and 0x4 should not be matched but starting at 0x5 you might use:

bErrorss*:s*0x(?:[5-9A-F]|[A-F0-9]{2,})b

Explanation

  • bErrorss*:s*
  • 0x Match literally
  • (?: Non capture group for the alternation
    • [5-9A-F] Match either a digit 5-9 or char A-F
    • | Or
    • [A-F0-9]{2,} Match 2 or more occurrences of a char A-F or a digit 0-9
  • ) Close the non capture group
  • b A word boundary

Regex demo

Or with a negative lookahead, asserting not 0 – 4 directly to the right:

bErrorss*:s*0x(?![0-4]b)[A-F0-9]+b

Regex demo

Answered By: The fourth bird
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.