Regex: Match uint_16 not zero (without negative lookahead)

Viewed 40

I need to match exactly two bytes for anything other than \x00\x00.

Is it possible to do it without using negative lookahead? (The Regex engine I use doesn't allow me to)

So as an example:

  • \x00\x00 isn't valid
  • \x30\x31 is valid

Thanks

1 Answers

I need to match exactly two bytes for anything other than \x00\x00

You may use this regex with 2 negated characters classes and an alternation:

^[^\x00]|[^\x00]$

RegEx Explained:

  • ^: Start
  • [^\x00]: Match anything except \x00
  • |: OR
  • [^\x00]: Match anything except \x00
  • $: End
Related