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.
\bmatches 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:If you don’t want the pattern to match with an alphanumeric character before it, you can add
\Bbefore it (so#$00anda $00would match, buta$00would not). You can also be more picky, and disallow only certain characters:See also: Word Boundaries