279 B
279 B
A positive number with an optional decimal part is (per previous task): pattern:\d+(\.\d+)?
.
Let's add the optional pattern:-
in the beginning:
let regexp = /-?\d+(\.\d+)?/g;
let str = "-1.5 0 2 -123.4.";
alert( str.match(regexp) ); // -1.5, 0, 2, -123.4