Regex Escape Tool - Match Literal Strings

Escape regular-expression metacharacters so user input is matched literally.

  • No length limits
  • No registration
  • Free forever
  • Your text never leaves your browser
Options
Output
Your result will appear here as you type.

What Are Regex Metacharacters?

A regular expression is a miniature language, and a small set of characters carries its syntax: the backslash itself, the caret and dollar sign that anchor a match, the period that matches any character, the pipe for alternation, the question mark, asterisk, and plus sign that control repetition, and the parentheses, square brackets, and curly braces that group and quantify. To match one of those characters literally you escape it — most often by prefixing it with a backslash, so a literal dot becomes the two-character sequence backslash-dot rather than a wildcard.

Which characters need escaping depends on context. Inside a character class, for example, the square brackets and most repetition operators lose their special meaning while the hyphen becomes a range operator, and some dialects give the same character different roles in different positions. This page applies the standard rules so that text typed by a user matches itself, and it shows the escaped result before you copy it into code.

When to Use Regex Escape

Escape whenever user input must be matched literally — a search box that treats the query as plain text, a find-and-replace over user content, a filter that highlights a username or product code, or log analysis where the pattern came from outside the code. Without escaping, a query containing a dot, an asterisk, or a parenthesis is read as pattern syntax and matches things the user never asked for — and a deliberately crafted input can match far more than intended.

If literal matching is all you need, a plain substring check is simpler and faster than a regular expression at all — indexOf and includes exist precisely for that. Reach for this escape tool when you need regex power around a literal value, and escape at the point where the value enters the pattern rather than assuming the surrounding code protects it.

Frequently asked questions

Do I need to escape the forward slash in regex?

Only when the forward slash is the pattern delimiter. JavaScript regex literals are written between slashes, so a literal slash inside the pattern must be escaped or it terminates the expression early. When you build the expression from a string — new RegExp in JavaScript, re.compile in Python, and most other engines — the slash has no special role and needs no escaping. The characters that still matter there are the metacharacters: the backslash, the dot, and the brackets must be escaped the same way regardless of delimiter.

Your text never leaves your browser

Every tool runs locally on your device. Nothing you paste is uploaded, stored, or tracked.