Regex Escape
Escape special characters in regular expressions to match them literally
About Regex Escaping
Regular expressions (Regex) use special characters (metacharacters) to define search patterns. When you want to match these special characters literally rather than their special meaning, you need to escape them.
The regex escape tool helps convert plain text into patterns that can be safely used in regular expressions, ensuring special characters are treated as literal characters rather than metacharacters.
Escape Rules Reference
| Character | Regex Meaning | Escaped Form | Description |
|---|---|---|---|
| . | Any char | \. | Matches any single character |
| * | Zero or more | \* | Previous element 0+ times |
| + | One or more | \+ | Previous element 1+ times |
| ? | Zero or one | \? | Previous element 0 or 1 time |
| ^ | Line start | \^ | Matches line start |
| $ | Line end | \$ | Matches line end |
| | | Alternation | \| | Matches left or right |
| \ | Escape | \\ | Escapes next character |
| [ ] | Char class | \[ \] | Defines character set |
| ( ) | Group | \( \) | Creates capture group |
| { } | Quantifier | \{ \} | Specifies repetition |
Common Use Cases
Searching Special Characters
When you need to search for text containing dots, asterisks, and other special characters.
Dynamic Pattern Building
Ensure user input is properly escaped when building regex patterns from it.
File Path Matching
Match file paths containing backslashes and dots.
URL Matching
Match URLs containing question marks, equals signs, and other special characters.
Usage Tips
- Inside character classes [], most metacharacters lose their special meaning
- Hyphen - needs escaping when in the middle of a character class, not at start or end
- Different programming languages may have slightly different regex implementations
- Using raw strings (like Python's r'') can simplify escaping
- Some characters like @ # are not metacharacters in standard regex and don't need escaping
Practical Examples
| Text to Match | Escaped Pattern |
|---|---|
| file.txt | file\.txt |
| $100.00 | \$100\.00 |
| C:\Users | C:\\Users |
| [name] | \[name\] |