I have a problem to define a regexp that matches floating point numbers but do NOT identify integers.
I have the following regular expression, which matches floating numbers.
(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)?
How can I modify the expression above so that it doesn’t match integers?
Here is a example of what should be matched:
3.3
.3
5E6
.2e-14
7E+3
4.
5.E2
1e2
If your regex flavor supports lookaheads, require one of the floating-point characters before the end of the number:
Additional reading.
Here is also a slightly optimized version:
We start with an optional
+or-. Then we require one of the characters.,eorEafter an arbitrary amount of digits. Then we also require at least one digit, either before or after the string. The we just match digits, an optional.and more digits. Then (completely optional) aneor anEand optional+or-and then one or more digits.