Start by accessing the buffers from scratch and enter the text of the test. enter some numbers, some identifiers containing numbers, some numbers with missing parts (e.g. .e12 ), etc. These will be our test tests and allow us to quickly experiment. Now run Mx re-builder to enter Regular Expression Mx re-builder mode, which will allow you to try any regular expression against the text of the current buffer to see if it matches. This is a very convenient mode; You can use it all the time. Note that since Emacs lisp requires you to add regular expressions to strings, you must double all your backslashes. You are already doing it right, but I'm not going to double them.
Thus, restricting the coincidence of numbers that are not part of the identifiers is quite simple. \ b will match word boundaries, so put one at either end of your regex so that it matches the whole word
You can match the floats by simply adding a period to the character class you started with, so that it becomes [0-9.] . Unfortunately, this may coincide with the period when everything is on it; what we really want is [0-9]*\.?[0-9]+ , which will correspond to 0 or more digits, followed by an additional period, followed by one or more digits.
Can a matching character be matched with [-+]? , so we get negative numbers.
To compare the indicators, we need an additional group: \(...\)? , and since we use this only for highlighting and really donβt need to highlight the contents of the group, we can do \(?:...\) , which will save the regular expression. Inside the group, we will need to match "e" ( [eE] ), an optional character ( [-+]? ) And one or more digits ( [0-9]+ ).
Combining all this: [-+]?\b[0-9]*\.?[0-9]+\(?:[eE][-+]?[0-9]+\)?\b Please note that I placed an optional character in front of the first word boundary, because the characters "+" and "-" create the word boundary.
db48x source share