Escape regexp
This commit is contained in:
9
snippets/escape-regular-expression.md
Normal file
9
snippets/escape-regular-expression.md
Normal file
@ -0,0 +1,9 @@
|
||||
### Escape regular expression
|
||||
|
||||
Use `replace()` to escape special characters.
|
||||
|
||||
```js
|
||||
escapeRegExp = s =>
|
||||
s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user