December 2023
Intermediate to advanced
242 pages
5h 28m
English
| Recipe 68 | Matching Floating-Point Numbers |
Suppose you aim to write a regex to match floating-point values because you want to extract stock prices from a string. Or perhaps you want to retrieve other values that have a floating-point representation, such as interest rates, sensor readings, temperatures, or coordinates (latitude and longitude).
You want to be able to specify whether the presence of the sign, integer, and fraction components is mandatory or optional. The regex to use depends on the optional components of the floating-point number. Therefore, this recipe offers different patterns as potential solutions.
Matching a floating-point value that has a sign, integer, and fraction components:
| | [+-]\d+\.\d+ |
Matching a floating-point ...
Read now
Unlock full access