344 B
344 B
An integer number is pattern:\d+
.
A decimal part is: pattern:\.\d+
.
Because the decimal part is optional, let's put it in parentheses with quantifier pattern:'?'
.
Finally we have the regexp: pattern:\d+(\.\d+)?
:
let reg = /\d+(\.\d+)?/g;
let str = "1.5 0 12. 123.4.";
alert( str.match(re) ); // 1.5, 0, 12, 123.4