I have a simple google sheets REGEXEXTRACT
function that extracts numbers from NFL lines and over unders.
Here's the problem: The function
=VALUE(REGEXEXTRACT(I3,"-*\d*.?\d+"))
properly extracts -13.5 from text Line: GB -13.5
But when I use the same function on the text O/U: 51.5
, it incorrectly extracts 51.0
Where is my regular expression failing me?
The problem with your current regex is that, as written, in the second case the leading portion of the pattern is not matching anything, and only the final \d+
matches the integer 51
(see the demo here). You see 51.0
in your Excel spreadsheet because the decimal component defaults to being zero. Please use this regex pattern instead:
-?\d+(?:\.\d+)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With