Regex Escape
Escape every regex metacharacter so your text matches literally.
Runs entirely in your browser.
Escape a String for a Regular Expression
About Regex Escape
Characters like . * + ? ^ $ { } ( ) | [ ] \ all mean something to a regex engine. To match them literally you have to put a backslash in front of each one - so a search for $9.99 needs to become \$9\.99, otherwise the dot matches any character and the dollar anchors to the end of the line.
This is what a language's own escape helper does: Python's re.escape, JavaScript has no built-in but the same character class is the convention. Reach for it whenever you build a pattern out of a value you did not write yourself.
Other Escaping Tools
- Escape / Unescape — every format on one page
- SQL Escape — quotes and backslashes for SQL literals
- XML Escape — the five reserved XML characters
- CSV Escape — quote a value for a CSV field
- Backslash Escape — newlines and tabs as \n and \t
- HTML Entities — encode and decode HTML entities
- URL Encode / Decode — percent-encoding
- JSON Stringify — escape JSON into a string literal