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 ❌ See crbug.com/353856236
- Chrome Android ❌ See crbug.com/353856236
- Edge ❌ See crbug.com/353856236
- Firefox ❌
- Firefox for Android ❌
- Safari 18.2 Released on 2024-12-11
- Safari on iOS 18.2 Released on 2024-12-11
Specifications
- RegExp.escape, from TC39 (Ecma International).