RegExp.escape()
RegExp.escape() is a JavaScript method in the RegExp category. Escapes special regex characters in a string. The syntax is RegExp.escape(str). A typical example: RegExp.escape("hello.world") // "hello\.world". A close sibling is RegExp.prototype.test(), which tests for a match in a string. A close sibling is RegExp.prototype.exec(), which executes a search for a match (with groups). A close sibling is RegExp.prototype.source, which returns the pattern text. A close sibling is RegExp.prototype.flags, which returns the flags as a string. More about this category: Regular expression methods for pattern matching. Related RegExp methods: RegExp.prototype.test(), RegExp.prototype.exec(), RegExp.prototype.source, RegExp.prototype.flags, RegExp.prototype.lastIndex, RegExp.prototype.global, RegExp.prototype.ignoreCase, RegExp.prototype.multiline. This page is part of the free JS Reference documentation covering 1027+ methods, each with syntax, parameters, return values, examples, and common pitfalls. You can try RegExp.escape() immediately in the JavaScript playground, look up unfamiliar terms in the glossary, or return to the JS Reference homepage.