Regex Escape Tool
Quick Access to Regex Tools
Go straight to the regex utility you need.
How to Use the Regex Escape Tool
Paste the regex pattern
Paste the regex pattern.
Click Escape
Click Escape.
Copy the escaped string
Copy the escaped string.
Regex Escape Tool — Escape Special Characters in Regular Expressions
Type .* into a regex engine and it won't look for a literal dot followed by a literal asterisk. Instead, it matches zero or more of any character. That's because . and * are metacharacters — they have special meaning in regex syntax. When you actually want to match these characters literally, like searching for the filename report.pdf or the string C:\Users, every special character needs a backslash in front of it. The Regex Escape Tool does this conversion for you automatically.
Feed it any text — a file path, a URL fragment, a mathematical expression, a user-provided string — and it returns the same text with all regex metacharacters properly escaped. Copy the result directly into your pattern and it will match the original text literally.
Which Characters Need Escaping and Why
There are 14 characters that are special in standard regex syntax: . * + ? ^ $ ( ) [ ] { } | \. Each one has a specific job. The dot matches any single character. The quantifiers *, +, and ? control repetition. ^ and $ anchor matches to the start or end of a line. Parentheses create capture groups, square brackets define character classes, curly braces set repetition counts, and the pipe acts as an alternation operator. The backslash itself is the escape character, so it needs escaping too.
Additionally, this tool escapes /, :, =, and ! because these characters can be problematic in certain contexts — particularly inside delimiters like /pattern/ in JavaScript and PHP, or in URL-related regex patterns.
Here's a quick reference of each metacharacter and what it does in a regex context. The . matches any character except newline (unless the s flag is set). The * quantifier matches zero or more of the preceding element, making it greedy by default. + matches one or more, and ? makes the preceding element optional (zero or one). The ^ anchor asserts the position at the start of the string or line, while $ asserts the end. Parentheses ( ) group subexpressions and create capture groups. Square brackets [ ] define a character class that matches any one of the enclosed characters. Curly braces { } specify exact or range-based repetition counts. The pipe | offers alternation — match the expression before it or the one after it. And the backslash \ escapes the next character, stripping its special meaning.
Real-World Scenarios Where Escaping Matters
User input from forms: If a user types price is $5.00 and you try to match it literally with price is $5.00, the $ is interpreted as an end-of-string anchor and the . matches any character. You need price is \$5\.00. This is one of the most common bugs in search-and-replace features. It's particularly insidious because the pattern often still "works" for some inputs — the dollar sign at the end of the pattern silently fails to match a literal dollar sign in the middle of text, so your search seems to work until you test it with a string where the difference matters.
File paths on Windows: A path like C:\Users\Documents\report.txt contains backslashes — which are regex escape characters — and dots, which are metacharacters. The escaped version becomes C:\\Users\\Documents\\report\.txt. Skip this step and the engine either throws a syntax error or matches something completely unexpected. Windows file paths are one of the most common sources of regex bugs precisely because the backslash character is overloaded — it means something different in the file system, in string literals, and in regex syntax.
URL parameters: Matching a query string like ?q=search&lang=en literally requires escaping the question mark, ampersand, and equals sign. Without escaping, ? makes the preceding token optional, = has special meaning inside some regex flavors, and the overall pattern falls apart. URL matching is a common task in web scraping, log analysis, and security testing, and getting the escaping wrong leads to patterns that silently match the wrong things.
Log file analysis: Log lines often contain IP addresses (192.168.1.1), timestamps with dots, and error codes with special characters. Searching for these patterns literally requires escaping every metacharacter to avoid false matches. A common mistake is searching for a timestamp like 2024.01.15 without escaping the dots — this matches 2024x01x15 just as easily as 2024.01.15.
SQL injection prevention: When you're building a regex to validate or sanitize SQL-like input, you often need to match literal SQL syntax characters — single quotes, percent signs, underscores in LIKE patterns. Escaping these in the regex ensures you're matching the literal characters rather than triggering regex metacharacter behavior. While escaping alone isn't a defense against SQL injection (use parameterized queries for that), it matters when you're writing patterns to audit or analyze SQL text.
Escaping in Different Contexts: SQL, HTML, and JavaScript
Escaping gets complicated when you layer multiple systems on top of each other. The regex engine has its own escape rules, the programming language has its own, and the output context (HTML, SQL, shell) may impose yet another layer. Understanding how these stack is critical for writing correct code.
In SQL: SQL uses backslash escaping in some databases (MySQL) but not others (PostgreSQL uses '' for escaping single quotes). When you're writing a regex to match SQL patterns, the regex itself doesn't care about SQL's escaping — but if the regex pattern lives inside a SQL query (for example, using a regex function in PostgreSQL or MySQL), you need to satisfy both SQL's string syntax and the regex engine's syntax simultaneously. A regex pattern like \badmin\b inside a MySQL query becomes a multi-layer escaping exercise: the regex needs the backslashes, but MySQL's string parser may consume them first.
In HTML: HTML uses character entity references like < for <, > for >, and & for &. When matching HTML content with regex, you're often dealing with text that has already been entity-encoded. A regex looking for the literal < character won't match < — you need to match either the literal character or the entity, depending on your use case. This is why the escape tool's output works at the regex level, but you still need to think about what the text looks like in its decoded form.
In JavaScript: JavaScript presents a unique dual-escaping challenge. Inside a regex literal /pattern/, the forward slash is a delimiter and must be escaped as \/. Inside a new RegExp() constructor, the pattern is a regular string, so every backslash must be doubled. The escape tool produces regex-level escaping, but when you embed the result in JavaScript source code, you may need to apply a second round of escaping depending on which constructor you use. This is a frequent source of bugs — a developer tests a pattern in the browser console using regex literal syntax, then pastes it into code using new RegExp() (or vice versa), and the pattern breaks silently.
In shell commands: When using regex in command-line tools like grep, sed, or awk, the shell itself interprets characters before the regex engine sees them. Single quotes in bash preserve literal character meaning, while double quotes allow variable expansion. A pattern like grep '\$5\.00' passes the literal string \$5\.00 to grep, which then interprets the backslashes as regex escapes. Without the shell quotes, the shell would try to expand $5 as a variable.
Escaped Patterns by Language
The characters that need escaping in the regex itself are the same across all languages. However, each language adds its own layer of string escaping on top. In a Java string, every backslash must be doubled, so a regex \. becomes \\. in Java source code. In Python raw strings (r'.'), the backslash is literal, so \. stays as-is. In C# regular strings, you double the backslash like Java. This tool handles the regex-level escaping — you may still need to adjust for your language's string literal rules, which our Regex to String Converter handles.
Perl gets special treatment because regex is embedded directly in the language syntax. A regex like /\$5\.00/ works without additional escaping because the / delimiters separate the regex from the string layer. Perl also supports the qr// operator for precompiled regex, which follows the same escaping rules as the // syntax.
Go uses standard string literals, but the regexp package accepts raw strings directly. Since Go strings don't interpret most escape sequences the same way Java does, the escaping requirements are somewhat different. However, Go's RE2-based engine doesn't support all the same features as PCRE, so a pattern that's syntactically correct after escaping might still fail if it uses features Go doesn't implement.
Ruby offers flexibility with multiple string delimiter types. Single-quoted strings, double-quoted strings, and the %q{} syntax each have different escaping behaviors. Single-quoted strings are the safest for regex — backslashes are literal except before \ and '. This makes Ruby one of the more forgiving languages for embedding regex patterns in source code.
Common Mistakes to Avoid
A frequent error is over-escaping: wrapping entire patterns in the escape tool when only a few characters actually need it. If your pattern is already a valid regex, running it through the escape tool will turn every metacharacter into a literal, breaking the pattern's logic. Use this tool when you have literal text that you want to match exactly — not when you're building patterns from scratch.
Another pitfall is forgetting that the hyphen inside a character class [a-z] is a range operator, not a literal hyphen. If you want to match a literal hyphen in a character class, place it first or last: [-a-z] or [a-z-]. Outside a character class, a hyphen doesn't need escaping at all.
Escaping the wrong layer: Developers sometimes try to escape characters for both the regex engine and the string layer simultaneously, ending up with quadruple backslashes where only double were needed. If you're using this tool's output and then also manually doubling backslashes for a Java string, you'll end up with \\\\. — which matches a literal backslash followed by any character, not a literal dot. Pick one layer to handle the escaping and stick with it.
Forgetting the dot in filenames: When searching for filenames like data.csv, people often escape the dot but forget that the rest of the string might also contain metacharacters. A filename like report (final).pdf contains parentheses, which are capture group syntax in regex. The escape tool handles this automatically, but if you're escaping by hand, remember to check every character — not just the obvious ones.
Escaping inside character classes: Inside a character class [...], most metacharacters lose their special meaning. The dot matches a literal dot, the asterisk matches a literal asterisk, and so on. The characters that still need escaping inside a class are: ] (closes the class), \ (escape character), ^ (negation if first), and - (range operator). Escaping characters that don't need it inside a character class doesn't break anything, but it's unnecessary noise that makes patterns harder to read.
Not escaping in search-and-replace features: Many text editors (VS Code, Sublime Text, Notepad++) and IDEs have search-and-replace with regex support. If a user types a search string containing ( or [ without escaping, the editor may throw an error or match nothing. This is one of the most common practical consequences of forgetting to escape — it affects developers and non-developers alike in everyday tools.
Special Characters Reference Table
For quick reference, here are all the characters this tool escapes and what they mean in a regex context. . matches any character (except newline). * matches zero or more of the preceding element. + matches one or more. ? matches zero or one (makes preceding element optional). ^ asserts start of string/line. $ asserts end of string/line. ( ) creates capture groups. [ ] defines character classes. { } specifies repetition counts. | provides alternation. \ escapes the next character. / is the delimiter in JavaScript/PHP regex literals. : and = appear in special group syntax like (?:...) and (?=...). ! can appear in negative lookahead syntax (?!...).
Outside of these characters, everything else in a regex is treated as a literal. Letters, digits, spaces, commas, semicolons — they all match themselves by default. This means that a string like hello world 123 doesn't need any escaping at all if you want to match it literally. Only the 17 characters listed above require special treatment.
Frequently Asked Questions
. matches any character, * is a quantifier, ^ and $ are anchors, and so on. To match the literal character instead of triggering its special meaning, you precede it with a backslash. Without escaping, a search for file.txt would match fileatxt or file-txt because the dot matches any character./ and !. This covers all mainstream regex flavors.\. becomes \\. in your source code. In Python, use raw strings (r'\.') to avoid doubling. In JavaScript, forward slashes need escaping inside /pattern/ delimiters but not inside new RegExp(). Our Regex to String Converter handles these language-specific adjustments automatically.[a-z], the hyphen defines a range. Outside a character class, a hyphen is a literal character and doesn't need escaping. To match a literal hyphen inside a character class, put it first or last: [-a-z] or [a-z-]. This tool escapes the hyphen regardless because it can be special in certain contexts./pattern/ literal, the forward slash / must be escaped as \/. Inside new RegExp("pattern"), you don't need to escape slashes, but you do need to double every backslash for the string literal layer. If the escaped output from this tool contains /, be aware of the delimiter context.\\. in regex matches a literal backslash followed by any character — not a literal dot. This is sometimes intentional (matching escaped characters in source code), but usually it's a mistake. If your output looks wrong, check whether characters have too many backslashes in front of them.[...]. The dot matches a literal dot, the asterisk matches a literal asterisk, and so on. The exceptions are: ] (closes the class), \ (escape character), ^ (negation when it's the first character), and - (range operator between characters). Escaping characters that don't need it inside a class is harmless but makes patterns harder to read.REGEXP operator uses a regex engine with its own escaping rules, and the pattern must also satisfy MySQL's string literal syntax. PostgreSQL's ~ operator uses POSIX regex inside standard SQL strings. In both cases, the regex-level escaping is what this tool provides, but you may need additional escaping for the database's string syntax — typically doubling backslashes in double-quoted strings or using the database's escape conventions.