en.javascript.info/10-regular-expressions-javascript/09-regexp-groups/4-find-decimal-numbers/solution.md
Ilya Kantor 62c507c78f ok
2017-03-19 20:40:47 +03:00

264 B

A positive number with an optional decimal part is (per previous task): pattern:\d+(\.\d+)?.

Let's add an optional - in the beginning:

let reg = /-?\d+(\.\d+)?/g;

let str = "-1.5 0 2 -123.4.";

alert( str.match(reg) );   // -1.5, 0, 2, -123.4