Omnikit
DevFilesMoneyAll tools
Ctrl K
Dev toolsFile toolsMoney calculatorsAll tools
HomeDeveloper toolsRegex Escape
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский

Regex Escape

dev

Escape text so a regex matches it literally in JavaScript, Python, PHP, Java, Go or .NET

Runs in your browser. Nothing you type is sent anywhere. Checked against sources on 16 Oct 2026.

Regex escaping puts a backslash before each character with a special meaning, so a pattern matches the text literally. The 14 characters to escape almost everywhere are . ^ $ * + ? ( ) [ ] { } | and the backslash. Each language adds a few more, and JavaScript and Java escape differently.

Next:
  • String Escape & Unescape Escape text for a JSON, JavaScript, Java, Python, SQL or CSV string, or unescape it
  • Regex Tester Test JavaScript regular expressions with live highlighting and a plain-English explanation

How to escape special characters in a regex

1

Paste the text the pattern must match exactly, or click Try an example.

2

Choose the language: JavaScript, Python, PHP, Java, Go, .NET or sed and grep.

3

Turn on One per line to match any one of several lines, joined with |.

4

Click Copy, or press Ctrl+Enter, and paste the pattern into your code.

About Regex Escape

In a regular expression, a dot means any character, a plus means one or more, and brackets start a set. To search for text that contains them, such as a price like $4.99 or a file name like report(1).pdf, every such character must be escaped. This tool does it the way each language's own escape function does, so the pattern behaves exactly as in your code.

Language Function it matches Notes
JavaScript RegExp.escape also escapes / and punctuation as \x codes; works with the u and v flags
Python re.escape only special characters, since Python 3.7
PHP preg_quote($s, '/') adds = ! < > : - # and the / delimiter
Java Pattern.quote wraps the text in \Q and \E
Go regexp.QuoteMeta the smallest set: \ . + * ? ( ) | [ ] { } ^ $
.NET Regex.Escape also spaces and #, for patterns that ignore white space
sed, grep POSIX basic syntax . [ \ * ^ $ and the / delimiter

One per line. Turn it on to escape each line separately and join them with |, so the pattern matches any entry in a list of words, URLs or file names. Blank lines and duplicates are dropped. In sed and grep the join is |, which GNU tools understand.

Proof, not trust. For JavaScript, the page runs the pattern in your browser's own engine and confirms it matches the text and nothing else. The JavaScript output is tested against the engine with and without the u and v flags, and the Python output against CPython's re.escape on 728 strings.

Putting the pattern inside a string literal is a second, separate step: a backslash in a Java or C# string must be doubled. The String Escape tool does that part.

Everything runs in your browser; nothing you paste is sent anywhere.

Frequently asked questions

Which characters need to be escaped in a regex?

The characters with a special meaning: . ^ $ * + ? ( ) [ ] { } | and the backslash itself. Inside a pattern they act as wildcards, anchors, repeats or groups, so a literal dot must be written \. and a literal plus \+. Some languages escape a few more, such as / in JavaScript and PHP, or spaces in .NET.

How do I match a literal dot in a regular expression?

Write a backslash before it: \. matches only a dot, while a bare . matches any character. So example.com as a pattern also matches examplexcom, and example\.com matches only the real domain. Inside square brackets a dot is already literal, so [.] works too.

Why does JavaScript escape letters and spaces as \x codes?

RegExp.escape writes a leading letter or digit, and punctuation such as - , = and spaces, as \x codes, so the result stays correct wherever it is inserted: after \0 or \c, inside a character class, or with the u and v flags. The pattern is longer but always matches the text literally.

What is the difference between re.escape and preg_quote?

Both put a backslash before special characters, but PHP's preg_quote also escapes = ! < > : - # and the delimiter you pass, usually /, and writes a NUL byte as \000. Python's re.escape escapes - & ~ # and white space as well. Each tool's output is valid only for its own engine.

How does Java's Pattern.quote work?

Pattern.quote wraps the text in \Q and \E, which tell Java's engine to read everything between them literally. If the text itself contains \E, Java closes the quote, adds an escaped \E and opens a new one. To use the result in Java source code, every backslash must then be doubled in the string literal.

How do I make a regex that matches any word from a list?

Escape each word and join them with a vertical bar: cat|dog|bird matches any of the three. Turn on One per line here, paste the list and every line is escaped and joined for you, with blank lines and duplicates dropped. Add ^( and )$ around it to match whole lines only.

Sources

  • ECMA-262, ECMAScript Language Specification, RegExp.escapeWhich characters JavaScript escapes, and how
  • Python documentation, re.escapePython escapes only special characters since 3.7
  • PHP Manual, preg_quoteThe characters PHP escapes, the delimiter and NUL
  • Java SE 21 API, Pattern.quote\Q...\E quoting
  • Go standard library, regexp.QuoteMetaThe characters Go escapes
  • .NET API, Regex.EscapeThe characters .NET escapes, white space included
  • POSIX.1-2024 Base Definitions, 9.3 Basic Regular ExpressionsSpecial characters in sed and grep patterns

Last verified 16 October 2026.

Rates and rules change; check the source before you rely on a figure.

Still stuck? Ask about Regex Escape and anybody who knows can answer. No account needed.

Open it set for: Python Regex Escape (re.escape) · List to Regex.

Same job, other tools: Query String Parser – Split a URL query string into a table of decoded parameters.

On the related tools: TSV to JSON – Convert tab-separated values, such as a paste from Excel, into JSON.

Related tools

All developer tools
Base64 Encode & DecodeText and files to Base64 and back, with URL-safe mode and image previewUnix Timestamp ConverterUnix timestamps to dates and dates to timestamps, in any time zoneJSON to TypeScriptGenerate TypeScript interfaces or types from a JSON sampleCSV to JSONConvert CSV to JSON and JSON to CSV, with a table previewYAML to JSONConvert YAML to JSON and JSON to YAML, with anchors resolvedURL Encoder / DecoderPercent-encode or decode text and URLs, and see every part of a linkColor ConverterHEX, RGB, HSL, HWB, OKLCH and CMYK in both directions, with a contrast checkNumber Base ConverterBinary, octal, decimal, hex and any base to 36, exact at any size, with two's complement
Was this tool helpful?
Omnikit

Small jobs, done in your browser. Free, fast and private. Files are never uploaded.

Files

  • Compress Image
  • Image to PDF
  • Merge PDF
  • Compress PDF
  • PDF to Word
  • Word to PDF

Dev

  • JSON Formatter & Validator
  • Base64 Encode & Decode
  • JWT Decoder, Verifier & Encoder
  • Password Generator
  • UUID Generator
  • Unix Timestamp Converter

Money

  • SIP Calculator
  • EMI Calculator
  • GST Calculator
  • FD Calculator
  • PPF Calculator
  • Lumpsum Calculator
EnglishالعربيةবাংলাDeutschEspañolFrançaisPolskiPortuguêsРусский
GuidesQuestionsAboutHow we checkLaw library (beta)PrivacyTermsDisclosureContactMore: Exam practice (UGC NET Paper 1)Runs in your browser. Nothing is uploaded. © 2026 Omnikit (theomnikit.com)