Regex Cheat Sheet by Language (JS, Python, PHP, Java, Go)

Most regex syntax is universal but each language has its quirks. Python supports named groups as (?P<name>); JavaScript uses (?<name>). Go's RE2 doesn't support lookbehinds. PHP's PCRE has its own flag set. This cheat sheet lists every common regex feature with its syntax in JavaScript, Python, PHP, Java, Go, and .NET side-by-side.

How to use the Regex Cheat Sheet by Language (JS, Python, PHP, Java, Go)

Browse the full reference or filter by keyword. Each row shows the feature's syntax in each language; columns highlight where they differ.

Why a regex is not always portable

The core of regular expressions — classes, quantifiers, groups — is shared, but every language ships a different engine with its own dialect. PHP uses PCRE, JavaScript uses ECMAScript, Python has its own re module, Java has java.util.regex, .NET has its own, and Go uses RE2. They disagree on named-group syntax, lookbehind support, inline flags, and how much Unicode they assume by default.

RE2 is the sharpest example: to guarantee linear-time matching, Go deliberately drops backreferences and lookarounds, so a pattern that works in PHP can simply fail to compile in Go. This side-by-side reference lines the features up across six languages so you can spot the quirk that is about to bite before you port a pattern.

Common use cases

  • Porting a pattern — translate a working regex from Python to Go or JavaScript without trial and error.
  • Code review — confirm a pattern uses syntax the target language actually supports.
  • Choosing a language for a job — decide whether you need lookbehind or backreferences before you start.
  • Polyglot teams — keep one mental model when you switch between back-end and front-end regex.
  • Learning the edge cases — see exactly where the dialects diverge instead of memorising them.

Frequently asked questions

Why does my pattern work on regex101 but fail in Go?

Go uses the RE2 engine, which has no lookahead, lookbehind, or backreferences. The PCRE and JavaScript modes most testers default to allow them, so a pattern that relies on those features will not compile under RE2.

How does named-group syntax differ between languages?

Python accepts (?P<name>...), while JavaScript, .NET, Java, and PCRE use (?<name>...). Mixing the two forms up is a common porting bug.

Does <code>\d</code> mean the same thing everywhere?

Not quite. In several engines \d matches only ASCII digits by default, but Python 3 and .NET can match Unicode digits unless you opt out. Always pin the behaviour you expect when input may be non-ASCII.

Which engine is fastest?

RE2 (Go) guarantees linear time and never catastrophically backtracks, which makes it safest for untrusted input. Backtracking engines (PCRE, Python, JavaScript) are often quicker on typical patterns but can blow up on pathological ones.
Embed this tool on your site

Free to embed, no attribution required (but appreciated). Paste this where you want the tool to appear: