Skip to content

Commit 4974ad9

Browse files
committed
fix
1 parent 8f27052 commit 4974ad9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11

2-
An integer number is `pattern:\d+`.
2+
An non-negative integer number is `pattern:\d+`. We should exclude `0` as the first digit, as we don't need zero, but we can allow it in further digits.
3+
4+
So that gives us `pattern:[1-9]\d*`.
35

46
A decimal part is: `pattern:\.\d+`.
57

68
Because the decimal part is optional, let's put it in parentheses with the quantifier `pattern:'?'`.
79

8-
Finally we have the regexp: `pattern:\d+(\.\d+)?`:
10+
Finally we have the regexp: `pattern:[1-9]\d*(\.\d+)?`:
911

1012
```js run
11-
let reg = /\d+(\.\d+)?/g;
13+
let reg = /[1-9]\d*(\.\d+)?/g;
1214

13-
let str = "1.5 0 12. 123.4.";
15+
let str = "1.5 0 -5 12. 123.4.";
1416

1517
alert( str.match(reg) ); // 1.5, 0, 12, 123.4
1618
```

5-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ An example of use:
66
```js
77
let reg = /your regexp/g;
88

9-
let str = "1.5 0 12. 123.4.";
9+
let str = "1.5 0 -5 12. 123.4.";
1010

11-
alert( str.match(reg) ); // 1.5, 0, 12, 123.4
11+
alert( str.match(reg) ); // 1.5, 12, 123.4 (ignores 0 and -5)
1212
```

0 commit comments

Comments
 (0)