Glossary · Definition
Regex flavors comparison
Regex isn’t one universal language — each engine has its own features. JavaScript ECMAScript (browser/Node): standard. Python re: similar + named groups. PCRE (PHP, Perl, Java): adds recursion + possessive quantifiers. Go RE2: linear-time guaranteed but no lookbehind / backreferences.
Definition
Regex isn’t one universal language — each engine has its own features. JavaScript ECMAScript (browser/Node): standard. Python re: similar + named groups. PCRE (PHP, Perl, Java): adds recursion + possessive quantifiers. Go RE2: linear-time guaranteed but no lookbehind / backreferences.
What it means
<strong>JavaScript ECMAScript</strong> regex: lookbehind (added in ES2018), named groups, Unicode property classes (<code>\p{Letter}</code>). No recursion, no possessive quantifiers. Used in browsers and Node. <strong>Python re</strong>: similar to JS, adds named-group dict access and conditional patterns. PCRE2 features available in <code>regex</code> module (third-party). <strong>PCRE</strong> (PHP, Java, .NET, Apache): full feature set including recursion (<code>(?R)</code>), possessive quantifiers (<code>*+</code>), branch reset, balancing groups (.NET only). Used in mod_rewrite, log analysis. <strong>Go RE2</strong>: based on RE2 engine, guarantees linear-time matching (no catastrophic backtracking), but cannot do lookbehind or backreferences. Trade features for safety.
Advertisement
Why it matters
Patterns that work in one engine may fail in another. Common gotchas: PCRE recursion <code>(?R)</code> doesn’t work in JS. JS positive lookbehind <code>(?<=...)</code> requires Node 10+. Go RE2 rejects lookbehind. When integrating regex from blog posts or Stack Overflow, always check whether it was written for your target engine. Server-side log processing using Go RE2 needs RE2-compatible patterns; PCRE patterns will fail.
Example
Recursion (PCRE only): <code>(?R)</code> matches the whole pattern recursively (used for nested-bracket matching). Translates to: not directly possible in JavaScript (need to use a parser instead). Lookbehind (JS, PCRE): <code>(?<=USD\s)\d+</code> matches digits after ‘USD ‘. Translates to: not possible in Go RE2 (use post-processing instead).
Related free tools
Frequently asked questions
Which engine is fastest?
Depends on pattern. PCRE is slowest in worst case (exponential backtracking on adversarial input). RE2 is consistently fast (linear). JavaScript varies — modern V8 has good optimizations for common patterns.
Should I use PCRE if available?
More features but slower in worst case. For untrusted input (user-submitted patterns), use RE2 or limit pattern complexity. For trusted patterns, PCRE’s features can simplify implementation.
What about ICU regex?
International Components for Unicode (ICU) regex is used by some platforms (Java’s java.util.regex is ICU-influenced). Excellent Unicode support. Less common in web/mobile contexts.
Related terms
- DefinitionRegex cheat sheetQuick regex reference. Character classes: <code>\d</code> digit, <code>\w</code> word, <code>\s</code> whitespace. Quantifiers: <code>*</code> 0+, <code>+</code> 1+, <code>?</code> 0-1, <code>{n,m}</code> range. Anchors: <code>^</code> start, <code>$</code> end, <code>\b</code> word-boundary. Groups: <code>(...)</code> capture, <code>(?:...)</code> non-capture, <code>(?<name>...)</code> named.
- DefinitionReDoS attacksReDoS (Regular Expression Denial of Service) is an attack where adversarial input causes a regex to take exponential time to evaluate, freezing the server. Caused by patterns with nested quantifiers like <code>(a+)+</code>. Defense: use linear-time engines (Go RE2), avoid nested quantifiers, or set timeouts.
- DefinitionRegexRegex (regular expressions) is a notation for describing patterns in text — used for searching, matching, replacing, splitting, and validating. Every language has a regex engine; the syntax mostly overlaps but has gotchas.