regex - How to extract floating point value from string in javascript? -
how extract value "-1.23" following string using js regex?
"hello-sdvf-1.23 23 4"
this code extracts "-1"
("hello-sdvf-1.23 23 4").match(/[-]\d+|\d+/)[0];
you need define pattern match decimal part also.
string.match(/-?\d+\.\d+/)
Comments
Post a Comment