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:
parent
633db6fbe9
commit
6fc5b2c555
1 changed files with 2 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue