Add missing 0s and an 'a', remove double spaces
This commit is contained in:
parent
5ba5f8b79b
commit
219e9dbbc5
1 changed files with 4 additions and 4 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
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue