en.javascript.info/10-regular-expressions-javascript/06-regexp-quantifiers/4-find-decimal-numbers/solution.md
Ilya Kantor e2443e8de6 ok
2017-03-19 16:59:53 +03:00

12 lines
330 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Целое число с необязательной дробной частью -- это `pattern:\d+(\.\d+)?`.
К этому нужно добавить необязательный `-` в начале:
```js run
var re = /-?\d+(\.\d+)?/g
var str = "-1.5 0 2 -123.4.";
alert( str.match(re) ); // -1.5, 0, 2, -123.4
```