.net – Regular expression to validate hex string


I'm using this simple regular expression to validate a hex string:


As you can see, I'm using a quantifier to validate that the string is 16 characters long. I was wondering if I can use another quantifier in the same regex to validate the string length to be either 16 or 18 (not 17).

Best Answer

I believe


will work.

This is nice because it generalizes to any even-length string.