Menu

gitpiper

escapeRegExp javascript Code Snippet in 2025

stringregexpintermediate

Last Updated: 1 February 2025

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\\)

javascript snippet similar to escapeRegExp For You in February 2025

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2025 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️