commit
08a08f7501
2 changed files with 5 additions and 5 deletions
|
@ -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
|
||||||
```
|
```
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue