Files
30-seconds-of-code/snippets/escapeRegExp.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

397 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Escape RegExp string,regexp intermediate 2017-12-17T17:55:51+02:00 2020-09-15T16:28:04+03:00

Escapes a string to use in a regular expression.

  • Use String.prototype.replace() to escape special characters.
const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
escapeRegExp('(test)'); // \\(test\\)