en.javascript.info/9-regular-expressions/11-regexp-groups/03-find-decimal-numbers/solution.md
2019-09-06 16:50:41 +03:00

11 lines
279 B
Markdown

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