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

18 lines
485 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+`.
Десятичная точка с дробной частью -- `pattern:\.\d+`.
Она не обязательна, так что обернём её в скобки с квантификатором `pattern:'?'`.
Итого, получилось регулярное выражение `pattern:\d+(\.\d+)?`:
```js run
var re = /\d+(\.\d+)?/g
var str = "1.5 0 12. 123.4.";
alert( str.match(re) ); // 1.5, 0, 12, 123.4
```