String.prototype.replace()
to escape special characters.const escapeRegExp = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
escapeRegExp('(test)'); // \\(test\\)
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️