RegExp.escape()Baseline · Newly available
The RegExp.escape() static method takes a string and replaces any characters that are potentially special characters of a regular expression with equivalent escape sequences. For example, RegExp.escape("[abc]") returns "\\[abc\\]".
Works in the latest version of every major browser, but older devices may not support it yet. Baseline since May 1, 2025.
Browser support
DesktopChrome
1–135Not supported
136+Supportedsince Apr 29, 2025
Current: 155Edge
12–135Not supported
136+Supportedsince May 1, 2025
Current: 154Firefox
1–133Not supported
134+Supportedsince Jan 7, 2025
Current: 157Safari
1–18.1Not supported
18.2+Supportedsince Dec 11, 2024
Current: 27MobileChrome Android
18–135Not supported
136+Supportedsince Apr 29, 2025
Current: 155Firefox Android
4–133Not supported
134+Supportedsince Jan 7, 2025
Current: 157Safari iOS
1–18.1Not supported
18.2+Supportedsince Dec 11, 2024
Current: 27How to use
Every current browser supports this, but it only became Baseline on May 1, 2025. Use it as a progressive enhancement, or keep a fallback if you support older devices.
Example
Full syntax and examples are on MDN: escape.
Feature detection
JS · check before using
if ("escape" in RegExp || ("prototype" in RegExp && "escape" in RegExp.prototype)) {
// RegExp.escape is available
}