I created this regex to match all integers and floats in polynomials.
This regex MATCHES:
- all integers
- all floats
All of the above + " not followed by "
- open parenthesis
- letters
GROUPS returned:
- SIGN: the sign of the integer or float matched, and empty string is returned if the sign is not provided
- INT: matches this group if the number is an integer
- FLOAT: matches this group if the number is a float
Note:
- the name of the groups are up to you, however "sign, int and float" are the most appropriate
- if the number is an integer, the float group (3) will NOT be matched
- if the number is a float, the integer group (2) will NOT be matched
so be careful when dealing with the order of the groups returned
If you want the other version where you don't matter if the number is int or float, then check this out ->