Skip to content

Commit 32e20fc

Browse files
committed
reg->regexp
1 parent 4232a53 commit 32e20fc

File tree

35 files changed

+132
-132
lines changed

35 files changed

+132
-132
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Answer: `pattern:\d\d[-:]\d\d`.
22

33
```js run
4-
let reg = /\d\d[-:]\d\d/g;
5-
alert( "Breakfast at 09:00. Dinner at 21-30".match(reg) ); // 09:00, 21-30
4+
let regexp = /\d\d[-:]\d\d/g;
5+
alert( "Breakfast at 09:00. Dinner at 21-30".match(regexp) ); // 09:00, 21-30
66
```
77

88
Please note that the dash `pattern:'-'` has a special meaning in square brackets, but only between other characters, not when it's in the beginning or at the end, so we don't need to escape it.

9-regular-expressions/08-regexp-character-sets-and-ranges/2-find-time-2-formats/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ The time can be in the format `hours:minutes` or `hours-minutes`. Both hours and
55
Write a regexp to find time:
66

77
```js
8-
let reg = /your regexp/g;
9-
alert( "Breakfast at 09:00. Dinner at 21-30".match(reg) ); // 09:00, 21-30
8+
let regexp = /your regexp/g;
9+
alert( "Breakfast at 09:00. Dinner at 21-30".match(regexp) ); // 09:00, 21-30
1010
```
1111

1212
P.S. In this task we assume that the time is always correct, there's no need to filter out bad strings like "45:67". Later we'll deal with that too.

9-regular-expressions/08-regexp-character-sets-and-ranges/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,18 @@ In the example below the regexp `pattern:[-().^+]` looks for one of the characte
130130

131131
```js run
132132
// No need to escape
133-
let reg = /[-().^+]/g;
133+
let regexp = /[-().^+]/g;
134134

135-
alert( "1 + 2 - 3".match(reg) ); // Matches +, -
135+
alert( "1 + 2 - 3".match(regexp) ); // Matches +, -
136136
```
137137

138138
...But if you decide to escape them "just in case", then there would be no harm:
139139

140140
```js run
141141
// Escaped everything
142-
let reg = /[\-\(\)\.\^\+]/g;
142+
let regexp = /[\-\(\)\.\^\+]/g;
143143

144-
alert( "1 + 2 - 3".match(reg) ); // also works: +, -
144+
alert( "1 + 2 - 3".match(regexp) ); // also works: +, -
145145
```
146146

147147
## Ranges and flag "u"

9-regular-expressions/09-regexp-quantifiers/1-find-text-manydots/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Solution:
33

44
```js run
5-
let reg = /\.{3,}/g;
6-
alert( "Hello!... How goes?.....".match(reg) ); // ..., .....
5+
let regexp = /\.{3,}/g;
6+
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....
77
```
88

99
Please note that the dot is a special character, so we have to escape it and insert as `\.`.

9-regular-expressions/09-regexp-quantifiers/1-find-text-manydots/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ Create a regexp to find ellipsis: 3 (or more?) dots in a row.
99
Check it:
1010

1111
```js
12-
let reg = /your regexp/g;
13-
alert( "Hello!... How goes?.....".match(reg) ); // ..., .....
12+
let regexp = /your regexp/g;
13+
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....
1414
```

9-regular-expressions/09-regexp-quantifiers/2-find-html-colors-6hex/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Then we can look for 6 of them using the quantifier `pattern:{6}`.
77
As a result, we have the regexp: `pattern:/#[a-f0-9]{6}/gi`.
88

99
```js run
10-
let reg = /#[a-f0-9]{6}/gi;
10+
let regexp = /#[a-f0-9]{6}/gi;
1111

1212
let str = "color:#121212; background-color:#AA00ef bad-colors:f#fddee #fd2"
1313

14-
alert( str.match(reg) ); // #121212,#AA00ef
14+
alert( str.match(regexp) ); // #121212,#AA00ef
1515
```
1616

1717
The problem is that it finds the color in longer sequences:

9-regular-expressions/09-regexp-quantifiers/2-find-html-colors-6hex/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ Create a regexp to search HTML-colors written as `#ABCDEF`: first `#` and then 6
55
An example of use:
66

77
```js
8-
let reg = /...your regexp.../
8+
let regexp = /...your regexp.../
99

1010
let str = "color:#121212; background-color:#AA00ef bad-colors:f#fddee #fd2 #12345678";
1111

12-
alert( str.match(reg) ) // #121212,#AA00ef
12+
alert( str.match(regexp) ) // #121212,#AA00ef
1313
```
1414

1515
P.S. In this task we do not need other color formats like `#123` or `rgb(1,2,3)` etc.

9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ An acceptable variant is `pattern:<!--.*?-->` -- the lazy quantifier makes the d
55
Otherwise multiline comments won't be found:
66

77
```js run
8-
let reg = /<!--.*?-->/gs;
8+
let regexp = /<!--.*?-->/gs;
99

1010
let str = `... <!-- My -- comment
1111
test --> .. <!----> ..
1212
`;
1313

14-
alert( str.match(reg) ); // '<!-- My -- comment \n test -->', '<!---->'
14+
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'
1515
```

9-regular-expressions/10-regexp-greedy-and-lazy/3-find-html-comments/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
Find all HTML comments in the text:
44

55
```js
6-
let reg = /your regexp/g;
6+
let regexp = /your regexp/g;
77

88
let str = `... <!-- My -- comment
99
test --> .. <!----> ..
1010
`;
1111

12-
alert( str.match(reg) ); // '<!-- My -- comment \n test -->', '<!---->'
12+
alert( str.match(regexp) ); // '<!-- My -- comment \n test -->', '<!---->'
1313
```

9-regular-expressions/10-regexp-greedy-and-lazy/4-find-html-tags-greedy-lazy/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
The solution is `pattern:<[^<>]+>`.
33

44
```js run
5-
let reg = /<[^<>]+>/g;
5+
let regexp = /<[^<>]+>/g;
66

77
let str = '<> <a href="/"> <input type="radio" checked> <b>';
88

9-
alert( str.match(reg) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
9+
alert( str.match(regexp) ); // '<a href="/">', '<input type="radio" checked>', '<b>'
1010
```

0 commit comments

Comments
 (0)