Merge pull request #628 from duianto/patch-1

Add a missing 0
This commit is contained in:
Ilya Kantor 2018-11-26 10:58:11 +03:00 committed by GitHub
commit 08a08f7501
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -15,15 +15,15 @@ let reg = /#([a-f0-9]{3}){1,2}/gi;
let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
alert( str.match(reg) ); // #3f3 #AA0ef #abc alert( str.match(reg) ); // #3f3 #AA00ef #abc
``` ```
There's minor problem here: the pattern found `match:#abc` in `subject:#abcd`. To prevent that we can add `pattern:\b` to the end: There's a minor problem here: the pattern found `match:#abc` in `subject:#abcd`. To prevent that we can add `pattern:\b` to the end:
```js run ```js run
let reg = /#([a-f0-9]{3}){1,2}\b/gi; let reg = /#([a-f0-9]{3}){1,2}\b/gi;
let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
alert( str.match(reg) ); // #3f3 #AA0ef alert( str.match(reg) ); // #3f3 #AA00ef
``` ```

View file

@ -8,7 +8,7 @@ let reg = /your regexp/g;
let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; let str = "color: #3f3; background-color: #AA00ef; and: #abcd";
alert( str.match(reg) ); // #3f3 #AA0ef alert( str.match(reg) ); // #3f3 #AA00ef
``` ```
P.S. This should be exactly 3 or 6 hex digits: values like `#abcd` should not match. P.S. This should be exactly 3 or 6 hex digits: values like `#abcd` should not match.