Web platform features explorer

RegExp.escape()

Newly available since 2025-05-01
Tags: javascript

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

Usage (according to Chrome Platform Status)

~0.539% of page loads. More data at chromestatus.

Specifications