Zero Signup ToolsFree browser tools

Developer Tools

Regex Escape Tool

Escape any literal string into a regex-safe pattern for JavaScript, PCRE, Python, Java, .NET, Go, Ruby, POSIX, and vim. Reverse direction included.

Quick samples

Common literal strings that contain regex metacharacters. Load one to see the escape in action.

Regex flavor

Pick the engine your pattern will run against. The escape set differs slightly by flavor; the output is always safe for the chosen engine.

Output wrap

Optionally wrap the escaped pattern with anchors, word boundaries, or a language-specific constructor call. The raw escaped pattern is always available below.

36 chars

Escaped pattern (JS)

Every regex metacharacter has been backslash-quoted so this pattern matches the input literally.

Input chars

36

Output chars

41

Characters escaped

5

Ready-to-paste snippets (JavaScript)

Common ways to use this escaped pattern in the chosen language. Every snippet uses the unwrapped escape as its core.

Inside new RegExp()

new RegExp("https:\\/\\/example\\.com\\/path\\?query=value", "g")

As a slash literal

/https:\/\/example\.com\/path\?query=value/g

Why regex escaping matters

  • Dots are not literal.

    In regex, . matches any character, so a pattern of 192.168.1.1 also matches 192a168b1c1. Escaping turns it into 192\.168\.1\.1.

  • User input is a risk.

    Pasting unescaped user input into a regex search opens you up to accidental matches and ReDoS. Escape any literal that came from outside before you compile it into a pattern.

  • Flavors differ.

    POSIX BRE treats parens, braces, and pipes as literal by default, so the safe escape set is smaller than for PCRE. Picking the wrong flavor can over- or under-escape your pattern.

  • Round-tripping is exact.

    Click Swap to move the escaped pattern back into the input and run Unescape. The result equals the original literal, byte for byte, on every flavor in this tool.

How to use

  1. Pick the regex flavor your code will use (JavaScript, PCRE, Python, Java, .NET, Go, Ruby, POSIX ERE, POSIX BRE, or vim).
  2. Paste the literal text you want to match into the left input, or tap a sample like a URL, Windows path, or IPv4 address.
  3. Read the regex-safe pattern on the right and choose an output wrap if you want anchors, word boundaries, or a language constructor call.
  4. Use Copy output, or copy one of the ready-to-paste snippets below for new RegExp(), re.compile(), Pattern.compile(), and similar.
  5. Switch to Unescape mode and click Swap to round-trip a pattern back to its original literal, byte for byte.

About this tool

Regex Escape Tool takes a literal string and produces a regex pattern that matches that exact string, with the correct escape rules for the engine you pick. Each regex flavor treats a slightly different set of characters as metacharacters: PCRE, JavaScript, Java, and Go share the standard set (backslash, caret, dollar, dot, pipe, question, star, plus, parens, square brackets, and braces); Python's re module and Ruby's Regexp.escape also escape the verbose-mode comment marker (#); .NET escapes whitespace and # so the pattern survives IgnorePatternWhitespace; POSIX ERE drops the brace escape; POSIX BRE keeps only a small set (dot, caret, dollar, star, square brackets, backslash) because parens, braces, plus, question, and pipe are literal by default in basic regex mode; vim escapes its magic-mode metas (dot, star, tilde, brackets, anchors, backslash, slash) so a literal is safe in search and :substitute. Pick a flavor and the output updates instantly, then choose how to wrap it: bare pattern, anchored with ^ and $ for a full-string match, surrounded by word boundaries to match as a whole word, or wrapped as a ready-to-paste new RegExp() call, re.compile(r"...") expression, or /pattern/g slash literal. Below the output, a snippets panel shows the exact one-liner you would use in the chosen language, including equivalents for re.escape(), Pattern.quote(), Regex.Escape(), regexp.QuoteMeta(), and Regexp.escape(). Reverse mode takes any escaped pattern this tool produces and decodes it back to the original literal, so you can round-trip a value or sanity-check a pattern someone else escaped for you. Newlines, tabs, and carriage returns are normalised to \n, \r, \t so the output stays on a single line and is safe to drop into source code. Up to fifty thousand characters of input are processed entirely in your browser; the literal text and the resulting pattern never touch a server.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools