Regex Converter
Convert a regular expression's syntax between PCRE (PHP), JavaScript, Python re, Go regexp (RE2), Java, and Ruby — named groups, backreferences, lookbehind, atomic groups, possessive quantifiers, inline flags and more — plus convert the flags string between each flavor's notation. Flags per pair, notes explain every change or incompatibility.
Input
Output
| Status | Note |
|---|---|
| No data yet | |
Guides
Regular expressions look almost identical across languages until they aren't. A named group in Python is (?P<name>...); the same idea in JavaScript is (?<name>...). A backreference to it is (?P=name) in one and \k<name> in the other. Add lookbehind, atomic groups, possessive quantifiers, and PCRE-only shortcuts like \R, and a pattern that works perfectly in PHP can throw a syntax error the moment you paste it into a Node.js script. The Regex Converter rewrites a pattern's syntax between six flavors — PCRE (PHP), JavaScript, Python re, Go regexp (RE2), Java, and Ruby — and converts its flags string to match, so you spend less time hand-translating punctuation and more time writing the actual pattern.
What it converts
- Named groups and backreferences —
(?P<name>...)/(?P=name)(PCRE, Python, Go) rewritten to(?<name>...)/\k<name>(JavaScript, Java, Ruby), and back. PCRE's\g{name}and Ruby's\k'name'normalize to whichever the target flavor uses. - Lookbehind
(?<=...)/(?<!...)passes through unchanged (shared syntax), with a note when the target only supports fixed-length lookbehind (Python, Ruby) or limited lookbehind (Java). - Atomic groups (
(?>...)) and possessive quantifiers (a++,a*+) are flagged as unconvertible where the target has no equivalent (JavaScript, Python, Go). - Comment groups (
(?#...)) and inline flags ((?i),(?imsx)) are stripped with a note where unsupported (JavaScript supports neither); conditional patterns ((?(1)yes|no)) are flagged as PCRE-only. - PCRE-only classes
\R,\h,\vexpand to portable equivalents ((?:\r\n|\n|\r),[\t ],[\n\r\f]) for every other flavor. - String anchors
\A/\zconvert to^/$only where genuinely unsupported (JavaScript). Go's RE2 engine actually supports\A/\znatively, so they pass through untouched for a Go target. - Flags — single letters (
gi,imsx), Python'sre.IGNORECASE | re.DOTALLstyle, and Java'sPattern.CASE_INSENSITIVE | Pattern.DOTALLstyle are parsed and re-emitted in the target's notation. Flags with no equivalent (JavaScript'sghas no PCRE counterpart) are dropped with an explanation rather than mistranslated.
Every changed or unsupported construct appears in the Conversion Notes table below the output, tagged Success, Warning, or Error.
A Ruby quirk worth knowing
Ruby's /m flag doesn't mean "multiline" like it does elsewhere — it means dot matches newline (what other flavors call "dotall"). Ruby has no separate multiline flag at all, because ^/$ always match at line boundaries by default. Converting Ruby's /m to another flavor correctly produces that flavor's dotall flag (s), not its multiline flag.
How to use it
- Paste your regex pattern and, optionally, its flags.
- Choose the Source Flavor it was written for and the Target Flavor you need.
- The converted pattern, converted flags, and a note for every change appear instantly — no button to click.
Limitations
This is a syntax and feature-compatibility rewriter, not a semantic guarantee. It doesn't execute either pattern, so subtler engine differences — Unicode property escapes, the exact whitespace sets inside \h/\v, or performance characteristics — aren't verified. Always test the converted pattern against real sample input in its target environment before shipping it.
Why does converting to PCRE sometimes drop my g flag?
g (global matching) isn't a pattern modifier in PHP's PCRE functions — global matching is a separate function (preg_match_all()), not a pattern flag. A literal g in a PHP modifier string throws an "Unknown modifier" error, so the converter drops it and explains why instead of producing a pattern that fails to compile.