I am working on a Python function that parses a string representing a SQL query and returns the numbers (both integers and floats). I need those to highlight the numbers in the GUI.
I use https://regex101.com/ to test the regular expressions I build and I have almost got it except when number is a part of a column name in the SQL query.
[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?
would include even pop1990
in 220, pop1990 in (5, 100, 7.8,25;)
which I want to avoid. It looks as I may need to use negations using ^
but not sure how it would work.
When searching for numbers, how do I exclude those cases when number comes right after a word character (\w
) but still match when it comes before or after (
, ,
, ;
and so forth?