RegExp.escape()
Limited availability
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\\]"
.
Learning resources on MDN
Browser support
- Chrome ❌
- Chrome Android ❌
- Edge ❌
- Firefox 134 Released on 2025-01-07
- Firefox for Android 134 Released on 2025-01-07
- Safari 18.2 Released on 2024-12-11
- Safari on iOS 18.2 Released on 2024-12-11
Usage (according to Chrome Platform Status)
~0.295% of page loads. More data at chromestatus.
Specifications
- RegExp.escape, from TC39 (Ecma International).
View web-platform-tests results for this feature - View the feature source file (dist) - Edit the feature - Report an issue about this feature