Regex Escape
Escape literal text for JavaScript regex and get pattern source, a RegExp constructor snippet or a Unicode regex literal.
This tool processes its input contents in your browser instead of sending them to a processing service. Page, asset and fixed usage-measurement requests are described on the Privacy page.
Turn literal text into an escaped ECMAScript pattern, RegExp constructor snippet or Unicode regex literal.
How to use it
- 1Paste the exact text you want a JavaScript pattern to match.
- 2Choose the output format and select Escape for JavaScript.
- 3Copy or download the escaped result and review it in your own code.
Example
- Input
- file-1.json
- Output
- \x66ile\x2d1\.json
The dot matches a dot. The first letter and the hyphen are hexadecimal escapes that match their original characters.
What happens to your data
The escaper creates pattern text locally without executing it. Pasted text and generated snippets are excluded from optional usage measurement.
Last updated November 2026
Make JavaScript regular expressions match text with punctuation literally. Paste a filename, label, log fragment or multiline string. Regex Escape generates a plain pattern, a ready-to-copy RegExp constructor snippet or a slash-delimited regex literal with the Unicode flag. Choose the output for where you will paste it, then copy or download the escaped result.
How it works
Characters like a dot, a question mark and parentheses have special meanings in a regular expression. Escaping gives the pattern a representation that matches those characters as text. The tool follows ECMAScript RegExp.escape rules, including hex escapes for some punctuation such as hyphens, the first ASCII letter or digit and spaces. The leading escape helps keep a pasted fragment separate from a preceding numeric or control escape in a larger valid pattern. Control whitespace such as tabs and newlines is written visibly. Unicode text is preserved where an escape is unnecessary.
Pattern source is the fragment itself. The RegExp constructor snippet wraps that fragment in a JavaScript string with the additional backslashes it needs. The regex literal uses slashes with the Unicode flag, and a slash in your input is already escaped inside that result. Both complete snippets match a literal substring. For a full-string check in your own program, use anchors and flags appropriate to your match.
This is an ECMAScript text escaper. Regex engines, string quoting rules and interpolation contexts differ, so check compatibility if you move the fragment to another language. It does not execute or repair existing expressions. The input limit is 16,000 UTF-16 code units. Spaces and line breaks supplied in the text box are part of the literal text. All escaping and snippet generation happen in the browser.
Worked example: Escape punctuation in a literal fragment
- Input
- file-1.json
- Result
- \x66ile\x2d1\.json
The dot matches a dot. The first letter and the hyphen are hexadecimal escapes that match their original characters.
Common use cases
- Create a JavaScript regex that finds a filename with literal dots and brackets.
- Keep search text literal when inserting it into a larger JavaScript pattern.
- Get the right backslashes for a RegExp constructor or a regex literal.
- Represent spaces and line breaks explicitly when matching log text.
Frequently asked questions
Why is the first ASCII letter or digit written as a hex escape?+
That spelling keeps it from extending an adjacent escape when you put the fragment into an appropriate larger pattern. The resulting escape still matches the original character.
Which output should I paste into JavaScript?+
Use RegExp constructor snippet for new RegExp or Regex literal with /u for a slash-delimited expression. Pattern source is for a tool or code path that already accepts a raw pattern.
Will the result match an entire string?+
The output represents the literal fragment, so it can match inside a longer string. Add appropriate anchoring in your own pattern for a full-string match.
Does this escape characters for Python, sed or a shell?+
This output targets ECMAScript. Other languages, shells and tools can require different escape and quoting rules.
Can I paste tabs, line breaks or Unicode?+
Yes. The generated pattern represents those characters literally, within the 16,000 UTF-16 code unit limit.
Standards and limitations
Related tools
Regex Tester
Test JavaScript regex, inspect capture groups, and preview replacements with a cancellable timeout.
JSON String Escape
Escape text to one JSON string or strictly decode it, preserving embedded text and numeric IDs.
HTML Entity Encode/Decode
Encode or decode HTML entities using named, decimal or hex forms, including the full HTML5 entity set.
Open Graph Generator
Build escaped Open Graph tags for a website with a local card preview and copyable HTML.