Text utilities

Regex Escape Tool

Escape text so it can be inserted as a literal pattern in common JavaScript regular expressions.

Text stays in your browserCopy your result
Text workspace
Text workspace

Edit on the left, review and copy the result on the right.

See the method

Your original text

Runs on your device

Your processed text

Your result

Let’s calculate.

Use the Calculate button to see your result.

Your content is processed locally.

How to use this tool

  1. Enter literal text.
  2. Select Update result to view the result.
  3. Check the method and assumptions below before using the result.

The method, explained

Prefix regular-expression metacharacters with a backslash. Also escape / for slash-delimited JavaScript patterns, and represent line breaks as escaped characters.

A WORKED EXAMPLE

Using literal text = Price (USD): $19.99 [sale], the result is Price \(USD\): \$19\.99 \[sale\]. Change these example inputs to match your task; use the method above to check each step.

Understanding your result

No. Replacement strings have different special sequences, such as $&. This output is for matching literal text in the pattern position.

What to keep in mind

This escapes a standalone pattern, not a character-class fragment or a replacement string. It does not execute a regular expression.

Common questions

Does it escape a replacement string too?

No. Replacement strings have different special sequences, such as $&. This output is for matching literal text in the pattern position.

Can I paste it directly inside a JavaScript string?

A source-code string may need another layer of backslash escaping. The output represents the regex pattern itself, not a quoted JavaScript string.

Methodology maintained by ClarityKit. How these tools are built and checked.