RegExp Escape
Turn a string into a pattern that matches those exact characters. The escapes followRegExp.escape in the ECMAScript spec.
The string never leaves the browser. Nothing is uploaded, and the string is not stored in the URL.
Copy uses the escaped pattern only. The summary below also shows the source and a new RegExp line.
Not escaped
Pattern
About this tool
RegExp.escape has been in the ECMAScript spec since the 2025 edition. A hand-rolled replace that only puts a backslash in front of . and* gets the easy cases wrong. A hyphen cannot be written as \-in a unicode-mode pattern, and a leading digit can be swallowed by a \1that sits in front of the escaped text.
Syntax characters and / get a backslash. The controls tab, newline, vertical tab, form feed, and carriage return use \t, \n,\v, \f, and \r. Other punctuation, space, and lone surrogates use \x or \u. The first character, when it is a digit or an ASCII letter, is always a \x escape.
The page stops at 100,000 characters. Paste the literal, copy the pattern, and pass it to new RegExp. To see what a pattern matches, use theregex tester.
Read more
Free books, courses, and software
Get my programming books, course editions, and complete software.
Get the download library →