I'm working on a project (website) where I would like to validate various forms of Binary numbers. The first of which that I'd like to tackle is some Regex expression that handles the various 'valid' ways of representing hexadecimal digits. They are:
- Leading '0x'
- Leading'$'
- Trailing 'h'
I'm just not sure how to handle this in Regex, as you can obviously only have ONE of the three options present at any one time:
This is the query that I've currently got:(0x)?)[0-9A-Fa-f]
- Works for the case of leading 0x
- (Obviously) doesn't detect leading $ or trailing h
- Not sure how to implement the 'only oone' functionality.
~~ Valid ~~
0xA, 0xa, 0x101, 0x747, 101h, $747
~~ Invalid ~~
A (just hexadecimal digit by itself), 0xa$ (Leading 0x and trailing h), $0xA (Leading $ and 0x)
Thanks :)