Correct example in 9.14 (Lookahead and lookbehind)

Without the `g` flag, we cannot say that the price is skipped.
Without the `\b` assertion, we will have the part of the price in the result.
This commit is contained in:
Vse Mozhe Buty 2020-12-09 22:37:29 +02:00
parent 633db6fbe9
commit 6fc5b2c555

View file

@ -54,7 +54,7 @@ The syntax is: `pattern:X(?!Y)`, it means "search `pattern:X`, but only if not f
```js run
let str = "2 turkeys cost 60€";
alert( str.match(/\d+(?!€)/) ); // 2 (the price is skipped)
alert( str.match(/\d+\b(?!€)/g) ); // 2 (the price is not matched)
```
## Lookbehind
@ -81,7 +81,7 @@ And, if we need the quantity -- a number, not preceded by `subject:$`, then we c
```js run
let str = "2 turkeys cost $60";
alert( str.match(/(?<!\$)\d+/) ); // 2 (skipped the price)
alert( str.match(/(?<!\$)\b\d+/g) ); // 2 (the price is not matched)
```
## Capturing groups