Skip to content

Commit 0697954

Browse files
committed
minor
1 parent 79f0463 commit 0697954

File tree

1 file changed

+7
-7
lines changed
  • 9-regular-expressions/01-regexp-introduction

1 file changed

+7
-7
lines changed

9-regular-expressions/01-regexp-introduction/article.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ From here on the color scheme is:
6565

6666

6767
````smart header="When to use `new RegExp`?"
68-
Normally we use the short syntax `/.../`. But it does not allow any variable insertions, so we must know the exact regexp at the time of writing the code.
68+
Normally we use the short syntax `/.../`. But it does not support variable insertions `${...}`.
6969

70-
On the other hand, `new RegExp` allows to construct a pattern dynamically from a string.
70+
On the other hand, `new RegExp` allows to construct a pattern dynamically from a string, so it's more flexible.
7171

72-
So we can figure out what we need to search and create `new RegExp` from it:
72+
Here's an example of a dynamically generated regexp:
7373

7474
```js run
75-
let search = prompt("What you want to search?", "love");
76-
let regexp = new RegExp(search);
75+
let tag = prompt("Which tag you want to search?", "h2");
76+
let regexp = new RegExp(`<${tag}>`);
7777

78-
// find whatever the user wants
79-
alert( "I love JavaScript".search(regexp));
78+
// finds <h2> by default
79+
alert( "<h1> <h2> <h3>".search(regexp));
8080
```
8181
````
8282

0 commit comments

Comments
 (0)