en.javascript.info/5-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/solution.md
Ilya Kantor 455d300d8d renames
2017-05-25 11:56:32 +03:00

16 lines
344 B
Markdown

An integer number is `pattern:\d+`.
A decimal part is: `pattern:\.\d+`.
Because the decimal part is optional, let's put it in parentheses with quantifier `pattern:'?'`.
Finally we have the regexp: `pattern:\d+(\.\d+)?`:
```js run
let reg = /\d+(\.\d+)?/g;
let str = "1.5 0 12. 123.4.";
alert( str.match(re) ); // 1.5, 0, 12, 123.4
```