en.javascript.info/10-regular-expressions-javascript/7-regexp-quantifiers/4-find-decimal-numbers/solution.md
2015-03-23 10:49:30 +03:00

13 lines
354 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.

Целое число с необязательной дробной частью -- это <code class="pattern">\d+(\.\d+)?</code>.
К этому нужно добавить необязательный `-` в начале:
```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
```