Regex Escape Tool

This tool escapes a string so it can be matched literally inside a regular expression, adding backslashes before the characters that regex treats as special. Regular expressions give certain characters special meaning: the dot matches any character, the asterisk and plus mean repetition, brackets and parentheses group and define sets, and so on. When you want to match one of those characters literally, as the actual character rather than its special function, you must escape it with a backslash. Building a regex that contains user input, a file path, a price, or any text with special characters is a common source of bugs and even security issues, because an unescaped special character changes what the pattern matches. Escaping the text first solves this. This tool does it for you. You paste your string, and the calculator inserts a backslash before every character that has special meaning in a regular expression, producing a version safe to drop into a pattern where it will match exactly. The result updates as you type and runs entirely in your browser. Use it when building a regex that must contain a literal piece of text, when constructing patterns dynamically from variables, or to avoid the bugs that come from unescaped special characters. The characters escaped are the standard regex metacharacters, including the dot, asterisk, plus, question mark, caret, dollar, braces, brackets, parentheses, pipe, backslash and forward slash. After escaping, the string can be inserted into a larger pattern and will match the original text character for character, with no special behaviour. This is exactly what programming languages do with their built-in regex-quote or escape functions, and doing it here lets you prepare a literal fragment by hand, or simply understand which characters need escaping and why. For any pattern that must include text you do not control, escaping first is the safe habit.

-

Escapes regex metacharacters: . * + ? ^ $ { } [ ] ( ) | \ and /. The result matches the original text literally inside a pattern. Runs entirely in your browser.

How it works

The tool scans your text and inserts a backslash before every character that has special meaning in a regular expression. These metacharacters, such as the dot, asterisk and brackets, would otherwise change what the pattern matches. After escaping, each is treated as a literal character, so the string matches itself exactly.

Worked example

The text price: $19.99 (incl. GST)? becomes price: \$19\.99 \(incl\. GST\)\? with backslashes added before the dollar sign, the dots, the parentheses and the question mark. Dropped into a regular expression, that escaped string matches the original text exactly, with none of those characters acting as special regex operators.

Related calculators

If you've found a bug, or would like to contact us, or learn more about James Graham and Calculate.co.nz.

Calculate.co.nz is partnered with Interest.co.nz for New Zealand's highest quality calculators and financial analysis.

All calculators and tools are provided for educational and indicative purposes only and do not constitute financial advice.

Calculate.co.nz is proudly part of the Realtor.co.nz group, New Zealand's leading property transaction literacy platform, helping Kiwis understand the home buying and selling process from start to finish. Whether you're a first home buyer navigating your first property purchase, an investor evaluating your next acquisition, or a homeowner planning to sell, Realtor.co.nz provides clear, independent, and trustworthy guidance on every step of the New Zealand property transaction journey.

Calculate.co.nz is also partnered with Health Based Building and Premium Homes to promote informed choices that lead to better long-term outcomes for Kiwi households.

Calculate.co.nz is hosted in Auckland via SiteHost new Zealand.

All content on this website, including calculators, tools, source code, and design, is protected under the Copyright Act 1994 (New Zealand). No part of this site may be reproduced, copied, distributed, stored, or used in any form without prior written permission from the owner.

© 2019 to 2026 Calculate.co.nz. All rights reserved.