Skip to content

Regex escape

Escape the characters with special meaning in a regular expression, so text matches literally.

Input
Output

Regex escape

A regular expression treats characters like . * + ? ^ $ { } ( ) | [ ] and \ as instructions, not literal text. Paste in a filename, a price, a URL or any string that happens to contain one of them, and this tool escapes every special character with a backslash so the result matches that exact text — nothing more, nothing less. Switch direction to unescape and it reverses the process: strip the backslashes back off a pattern to recover the plain string it came from.

The dialect option decides which characters actually need escaping. JavaScript and PCRE share the same core metacharacter set, so a pattern built for one behaves the same in the other. POSIX Basic Regular Expressions — the default for plain grep and sed — are narrower: + ? { } ( ) and | are ordinary literal characters there, not metacharacters, so escaping them is skipped rather than applied blindly. Turn on "escape delimiter" when the pattern will be written between slashes, like /pattern/, so a literal / doesn't end the pattern early.

Two options handle multi-line input. "Each line as its own pattern" wraps every line in ^ and $, turning a list of exact strings into whole-line-matching patterns — handy for building an allowlist or blocklist entry by entry. "Join lines into one alternation" goes further, combining every line into a single (?:a|b|c) group ready to drop straight into one regex. Unescaping reverses both: it splits an alternation back into lines and strips the anchors off, so recovering the source list from a built pattern is one click.

Everything runs locally in your browser. The text and patterns you paste — including filenames, tokens or paths you'd rather not upload — are never sent anywhere; escaping happens entirely on your device.

FAQ

Which characters does this tool escape?
The regex metacharacters . * + ? ^ $ { } ( ) | [ ] and \. Exactly which of those need a backslash depends on the dialect you pick — POSIX BRE, for example, treats + ? { } ( ) and | as already literal.
What's the difference between the JavaScript, PCRE and POSIX dialects?
JavaScript and PCRE (Perl-compatible regex, used by many languages and tools) share the same metacharacter set for escaping. POSIX here means a Basic Regular Expression, the default for plain grep and sed, where + ? { } ( ) and | are ordinary characters rather than metacharacters — so they're left unescaped.
What does "join lines into one alternation" produce?
It escapes each line and combines them into a single group like (?:cat|dog|bird), ready to use as one pattern that matches any of the lines. Switching to unescape splits a pattern in that exact shape back into separate lines.
Will unescaping ever fail or throw an error?
No. Unescaping only removes a backslash that sits directly before a recognized special character; any other backslash sequence, or a malformed alternation wrapper, is left exactly as typed rather than raising an error.
Is my text uploaded anywhere?
No. Escaping and unescaping run entirely in your browser — nothing you paste here is sent to a server.