utilities.dev

Regex Escape

Escape special regex characters so your string matches literally in a pattern.

Escaping runs in your browser; output is suitable for JavaScript regex but engine behavior may differ elsewhere.

Input
Enter the string to escape for use as a literal regex pattern
Output
Escaped string safe for use in regex patterns

How to use this tool

  1. Paste or type the string you want to use as a literal regex pattern.
  2. Click Escape to add backslashes before special characters.
  3. Copy the escaped result and paste it into your regex or code.

About Regex Escape

This tool escapes characters that have special meaning in regex (e.g. . * + ? [ ] ( ) | \), so you can safely match user input or file paths as literal text. It is useful when building dynamic patterns from untrusted strings.

Common use cases

  • Escaping user search input before using it in a regex pattern
  • Converting file paths or URLs into literal match patterns
  • Preparing strings for RegExp constructors or replace operations

FAQ

What does regex escaping do?
It adds backslashes before characters that have special meaning in regex (like . * + ? [ ] ( ) | \), so the pattern matches those characters literally instead of as regex metacharacters.
Does this tool send my text anywhere?
No, escaping runs entirely in your browser. Your input never leaves your device.
Will the escaped output work in all regex engines?
The output follows JavaScript regex escaping rules. Other engines (PCRE, Python, etc.) may have slightly different special character sets, so test in your target environment.
When should I escape vs. use a regex directly?
Escape when your pattern comes from user input, config, or file paths. Use raw regex when you control the pattern and want metacharacters like . or * to have their special meaning.

Related tools