Files
30-seconds-of-code/snippets/escape-reg-exp.md
Stefan Feješ b848906fe5 fix naming
2017-12-17 15:41:31 +01:00

9 lines
200 B
Markdown

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