Skip to content

Commit 6fc5b2c

Browse files
committed
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.
1 parent 633db6f commit 6fc5b2c

File tree

1 file changed

+2
-2
lines changed
  • 9-regular-expressions/14-regexp-lookahead-lookbehind

1 file changed

+2
-2
lines changed

9-regular-expressions/14-regexp-lookahead-lookbehind/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The syntax is: `pattern:X(?!Y)`, it means "search `pattern:X`, but only if not f
5454
```js run
5555
let str = "2 turkeys cost 60€";
5656

57-
alert( str.match(/\d+(?!€)/) ); // 2 (the price is skipped)
57+
alert( str.match(/\d+\b(?!€)/g) ); // 2 (the price is not matched)
5858
```
5959

6060
## Lookbehind
@@ -81,7 +81,7 @@ And, if we need the quantity -- a number, not preceded by `subject:$`, then we c
8181
```js run
8282
let str = "2 turkeys cost $60";
8383

84-
alert( str.match(/(?<!\$)\d+/) ); // 2 (skipped the price)
84+
alert( str.match(/(?<!\$)\b\d+/g) ); // 2 (the price is not matched)
8585
```
8686

8787
## Capturing groups

0 commit comments

Comments
 (0)