fix
This commit is contained in:
parent
8f2705253a
commit
4974ad9fa7
2 changed files with 8 additions and 6 deletions
|
@ -1,16 +1,18 @@
|
||||||
|
|
||||||
An integer number is `pattern:\d+`.
|
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.
|
||||||
|
|
||||||
|
So that gives us `pattern:[1-9]\d*`.
|
||||||
|
|
||||||
A decimal part is: `pattern:\.\d+`.
|
A decimal part is: `pattern:\.\d+`.
|
||||||
|
|
||||||
Because the decimal part is optional, let's put it in parentheses with the quantifier `pattern:'?'`.
|
Because the decimal part is optional, let's put it in parentheses with the quantifier `pattern:'?'`.
|
||||||
|
|
||||||
Finally we have the regexp: `pattern:\d+(\.\d+)?`:
|
Finally we have the regexp: `pattern:[1-9]\d*(\.\d+)?`:
|
||||||
|
|
||||||
```js run
|
```js run
|
||||||
let reg = /\d+(\.\d+)?/g;
|
let reg = /[1-9]\d*(\.\d+)?/g;
|
||||||
|
|
||||||
let str = "1.5 0 12. 123.4.";
|
let str = "1.5 0 -5 12. 123.4.";
|
||||||
|
|
||||||
alert( str.match(reg) ); // 1.5, 0, 12, 123.4
|
alert( str.match(reg) ); // 1.5, 0, 12, 123.4
|
||||||
```
|
```
|
||||||
|
|
|
@ -6,7 +6,7 @@ An example of use:
|
||||||
```js
|
```js
|
||||||
let reg = /your regexp/g;
|
let reg = /your regexp/g;
|
||||||
|
|
||||||
let str = "1.5 0 12. 123.4.";
|
let str = "1.5 0 -5 12. 123.4.";
|
||||||
|
|
||||||
alert( str.match(reg) ); // 1.5, 0, 12, 123.4
|
alert( str.match(reg) ); // 1.5, 12, 123.4 (ignores 0 and -5)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue