Regex Escape

Regex Escape

Escape plain text for safe use inside regular expressions with normal-pattern and character-class modes. Perfect for building dynamic regex safely, filtering user input, and generating reliable literal matches in code.

regex
escape
pattern
Share this tool:
Quick Presets
Text to escape for regex use
Input
Paste text containing special characters to escape for use in regular expressions.
How it works: Escapes special regex characters in your input text so it can be safely used as a literal pattern in regular expressions.

Complete Guide: Regex Escape

Everything you need to know about using this tool effectively

What is Regex Escape Tool?

The Regex Escape Tool adds backslash escapes to characters that have special meaning in regular expressions. You paste a string containing characters like ., *, +, ?, ^, $, {, }, (, ), |, [, ], or \, and the tool prefixes each one with a backslash so it is treated as a literal character in a regex pattern. All processing happens in the browser.

This tool scans your input string and inserts a backslash before every character that is reserved in regex syntax. The escaped output can be used directly in a RegExp constructor or regex pattern without triggering unintended metacharacter behavior.

Key Features
Escapes all regex metacharacters
Handles . * + ? ^ $ { } ( ) | [ ] \
Preserves non-special characters unchanged
Copy escaped string to clipboard
Shows which characters were escaped
Real-time processing
Runs in the browser with no uploads
Handles strings of any length
Common Use Cases
When and why you might need this tool

Searching for literal text in code with regex

Escape a string like 'file.txt' so the dot is treated as a literal character, not a wildcard.

Building dynamic regex patterns

Escape user input before inserting it into a regex pattern to prevent regex injection.

Writing regex for file paths

Escape backslashes and dots in Windows file paths for use in regex matching.

Creating test fixtures

Generate escaped strings for unit tests that verify regex escaping logic.

How to Use This Tool
Step-by-step guide to get the best results
1

Paste your string

Enter the text containing characters you want to escape.

2

Escape

Click Escape. The tool adds backslashes before all regex metacharacters.

3

Copy the result

Copy the escaped string for use in your regex pattern.

Pro Tips
1

Always escape user input before using it in a regex to prevent injection.

2

The tool escapes the following characters: . * + ? ^ $ { } ( ) | [ ] \.

3

Non-special characters are left unchanged.

4

The escaped string can be used directly in new RegExp() or /pattern/.

Frequently Asked Questions
Which characters are escaped?

The tool escapes all characters with special meaning in regex: period, asterisk, plus, question mark, caret, dollar sign, curly braces, parentheses, pipe, square brackets, and backslash.

Why do I need to escape regex characters?

Regex metacharacters have special meanings (like . matching any character). Escaping them with a backslash tells the regex engine to treat them as literal characters.

Is my string uploaded to a server?

No. All processing happens in your browser using JavaScript. The string never leaves your device.

Can I use the output directly in JavaScript?

Yes. The escaped string can be passed to new RegExp() or used in string methods like match() and replace().

Does it handle Unicode characters?

Yes. Non-ASCII characters and Unicode text are preserved unchanged since they are not regex metacharacters.