I have created a regex for highlighting certain assembly-styled hex numbers which are like this:
$00
$1400
$FFFFFF
Sometimes they are preceeded with a # as well. So I created this regex as a start:
@"\b(\$)[A-Fa-f\d]+\b"
When I tried it out, it didn't seem to match anything. However, if I replace the \$ with 0x, it works fine and returns matches for C# style hex-numbers like 0x0F, 0xFF, etc.
Why is this? I have spent a few hours trying to make this regex work but I just can't and have no idea why. Any help would be appreciated.
\b
matches between an alphanumeric character and a non-alphanumeric character - it does not match between $
and #
, space, or other characters. You may want to drop it entirely:
@"(\$)[A-Fa-f\d]+\b"
If you don't want the pattern to match with an alphanumeric character before it, you can add \B
before it (so #$00
and a $00
would match, but a$00
would not). You can also be more picky, and disallow only certain characters:
@"(?<=[\w$])(\$)[A-Fa-f\d]+\b"
See also: Word Boundaries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With