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.
Complete Guide: Regex Escape
Everything you need to know about using this tool effectively
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.
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.
Paste your string
Enter the text containing characters you want to escape.
Escape
Click Escape. The tool adds backslashes before all regex metacharacters.
Copy the result
Copy the escaped string for use in your regex pattern.
Always escape user input before using it in a regex to prevent injection.
The tool escapes the following characters: . * + ? ^ $ { } ( ) | [ ] \.
Non-special characters are left unchanged.
The escaped string can be used directly in new RegExp() or /pattern/.
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.