Escape regexp

This commit is contained in:
Angelos Chalaris
2017-12-10 16:55:32 +02:00
parent 542a08cf2a
commit 2fa6e7bba8
2 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,9 @@
### Escape regular expression
Use `replace()` to escape special characters.
```js
escapeRegExp = s =>
s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
```