reg->regexp

This commit is contained in:
Ilya Kantor 2019-09-06 16:50:41 +03:00
parent 4232a53219
commit 32e20fc97c
35 changed files with 132 additions and 132 deletions

View file

@ -2,8 +2,8 @@
Solution:
```js run
let reg = /\.{3,}/g;
alert( "Hello!... How goes?.....".match(reg) ); // ..., .....
let regexp = /\.{3,}/g;
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....
```
Please note that the dot is a special character, so we have to escape it and insert as `\.`.

View file

@ -9,6 +9,6 @@ Create a regexp to find ellipsis: 3 (or more?) dots in a row.
Check it:
```js
let reg = /your regexp/g;
alert( "Hello!... How goes?.....".match(reg) ); // ..., .....
let regexp = /your regexp/g;
alert( "Hello!... How goes?.....".match(regexp) ); // ..., .....
```

View file

@ -7,11 +7,11 @@ Then we can look for 6 of them using the quantifier `pattern:{6}`.
As a result, we have the regexp: `pattern:/#[a-f0-9]{6}/gi`.
```js run
let reg = /#[a-f0-9]{6}/gi;
let regexp = /#[a-f0-9]{6}/gi;
let str = "color:#121212; background-color:#AA00ef bad-colors:f#fddee #fd2"
alert( str.match(reg) ); // #121212,#AA00ef
alert( str.match(regexp) ); // #121212,#AA00ef
```
The problem is that it finds the color in longer sequences:

View file

@ -5,11 +5,11 @@ Create a regexp to search HTML-colors written as `#ABCDEF`: first `#` and then 6
An example of use:
```js
let reg = /...your regexp.../
let regexp = /...your regexp.../
let str = "color:#121212; background-color:#AA00ef bad-colors:f#fddee #fd2 #12345678";
alert( str.match(reg) ) // #121212,#AA00ef
alert( str.match(regexp) ) // #121212,#AA00ef
```
P.S. In this task we do not need other color formats like `#123` or `rgb(1,2,3)` etc.