Regex Escape Tool
Need to match a price like “$9.99 (incl. VAT)” or a file path inside a regular expression? Paste the text, choose the language, and get it with every special character escaped so it matches literally. PHP escaping includes your delimiter, a replacement-string mode doubles dollar signs, and you can wrap the result as a ready-to-paste string literal.
- Runs in your browser
- No sign-up
- Free to use
How to use Regex Escape Tool
- Paste the text you want to match exactly.
- Choose the regex flavour of your language or tool.
- For PHP, set the delimiter; optionally show a string literal.
- Copy the escaped pattern into your code.
Regex Escape Tool features
Seven flavours
JavaScript, PHP PCRE, Python, Java, .NET, Go RE2 and POSIX ERE.
Delimiter aware
Escapes the PHP delimiter like preg_quote().
Replacement strings
Doubles $ so it is inserted literally in String.replace().
String literals
Wraps the pattern with the quoting the language needs.
Self-check
Verifies the JavaScript result against the text.
Private
Runs in your browser.
When to use Regex Escape Tool
- Searching for user input inside a regex.
- Matching file paths, URLs or prices exactly.
- Building patterns from configuration values.
- Fixing bugs where a dot or bracket matched too much.
Regex Escape Tool FAQ
Which characters are special in regular expressions?
Typically . * + ? ^ $ { } ( ) | [ ] and the backslash. Some flavours add more: PHP treats the delimiter and # in extended mode as special; Python’s re.escape also escapes spaces and some punctuation.
Why escape the PHP delimiter?
PHP patterns are written between delimiters such as /…/. An unescaped delimiter inside ends the pattern early. preg_quote() takes the delimiter as a second argument for this reason.
What is a replacement string?
The second argument of replace functions. In JavaScript, $ followed by certain characters inserts captured groups; to insert a literal $, write $$.
Should I escape user input before putting it in a regex?
Always. Unescaped input can change the meaning of the pattern and, in some engines, cause catastrophic backtracking.
Does escaping change the string itself?
No. Escaping only changes how the pattern is written; the regex still matches the original text.
Is there a built-in function in my language?
PHP has preg_quote(), Python re.escape(), Java Pattern.quote(), .NET Regex.Escape() and Go regexp.QuoteMeta(). JavaScript has RegExp.escape() in the newest engines only.
Literal text in a pattern language
Regular expressions are a small language in which many punctuation marks have meaning. A dot matches any character, brackets define sets, parentheses group, a dollar sign anchors the end. When you want to match text that contains these characters literally, every one of them must be preceded by a backslash.
Each regex flavour has a slightly different list of special characters and a different way of embedding patterns in code. PHP wraps patterns in delimiters that must be escaped inside; Java and C# patterns live inside string literals where the backslash itself must be doubled; POSIX tools use a smaller set of metacharacters. The tool applies the rules of the flavour you choose.
Escaping is also a security measure. Building a pattern from user input without escaping lets the user inject regex syntax, which can change results or trigger catastrophic backtracking that ties up the server. Every language offers an escape function for this reason; this tool shows what it produces.
Replacement strings have their own small syntax. In JavaScript’s replace(), sequences such as $1 and $& are substitutions, so a literal dollar sign must be written as $$. The replacement mode does that for you.