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\\]"
.
Compatibility
- Chrome ❌ See crbug.com/353856236
- Chrome Android ❌ See crbug.com/353856236
- Edge ❌ See crbug.com/353856236
- Firefox ❌ Search for bugs Search for standards position
- Firefox for Android ❌ Search for bugs Search for standards position
- Safari ❌ Search for bugs Search for standards position
- Safari on iOS ❌ Search for bugs Search for standards position
Specifications
- RegExp.escape, from TC39 (Ecma International).