I’m working with a syntax highlighting control and I have to specify all of the highlighted stuff with Regex. I’ve completed everything else (keywords, functions, strings, comments, etc.) already but I can’t come up with a good rule for magic numbers. I’m using it for a Lua text editor if that helps at all.
I’m currently using \d+ to detect the digits but the problem is that I end up with things like this:

As you can see, my variable names are also getting parts of them highlighted.
Does anybody know of a way to make this particular rule work correctly?
You don’t want it to match within a name, so add a word boundary:
\b\d+\b.For floats, there could be a fractional part:
\b\d+(?:\.\d+)?\b.For floats, there could also be an exponent:
\b\d+(?:\.\d+)?(?:[Ee][+\-]?\d+)\b.