I have a string that looks something like this
Hey this is my 1.20 string
I’m trying to just extract 1.20 from it.
What’s the best way to do this?
I’ve tried something like this, but I get the value of 1.20,20 rather than just 1.20
var query = $(".query_time").html();
var matches = query.match(/\d.(\d+)/);
The result of the match function is an array, not a string. So simply take
BTW, you should also escape the dot if you want to have more precise match :
or this if you want to accept commas (depends on the language) :
But the exact regex will be based on your exact needs, of course and to match any number (scientific notation ?) I’d suggest to have a look at more complex regex.