Regex Engines
- https://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines
- https://gist.github.com/CMCDragonkai/6c933f4a7d713ef712145c5eb94a1816
- https://www.regular-expressions.info/quickstart.html
- An NFA engine is pattern driven and supports backtracking
- A DFA engine is text driven and doesn’t support backtracking
- A Thompson NFA uses an NFA structure but simulates states simultaneously in parallel, meaning it executes like a DFA without backtracking
Regex Engine Families
Perl Compatible Family
- Traditional NFA
- Driven by backtracking machine architecture
- Supports advanced features: Lookarounds, Backreferences, non-greedy quantifiers, atomic grouping
- Can exhibit exponential time complexity (susceptible to ReDoS / Catastrophic Backtracking)
PCRE2(Perl Compatible Regular Expression)- powers
PHP,R,Git, Apache HTTP Server, Nginx - Shared Library:
libpcre2 - https://github.com/PCRE2Project/pcre2
- powers
Oniguruma/Onigmo- original implementation has been archived
- powers
Ruby, VSCode syntax tokenization, TextMate, Sublime Text,jq,bat
java.util.regexfromJava- does not support POSIX character classes
- supports Unicode property escapes like
\p{Letter}
refromPython- does not support Unicode property escapes
ECMAScript family
- Similar to Perl-Compatible/Traditional NFA Family
- Standardized by ECMA-262 spec
- No possessive quantifiers, atomic groups
- Can exhibit exponential time complexity (susceptible to ReDoS / Catastrophic Backtracking)
- Does not support POSIX character classes like
[[:alnum:]] Irregexp- embedded in
V8engine - powers chromium based browsers,
Node.js,Deno
- embedded in
YARR(Yet Another Regex Runtime)- embedded in
JavascriptCoreengine - powers Apple Safari, Webkit frameworks,
Bun
- embedded in
POSIX Family
- Hybrid NFA/DFA
- prioritizes POSIX standard compliance over raw performance
- Enforces the Leftmost-Longest rule (immune to ReDoS unless tracking backreferences)
- Doesn’t support Unicode property escapes
- powers Unix Tools like
grep,sed,awk
Thompson NFA Family
- Linear Time Family
- Intentionally omits features requiring arbitrary backtracking like lookarounds and backreferences
- Guarantees O(n) matching time, n = length of string
re2written in C++ from Google- powers
Go(regexppackage) - https://github.com/google/re2
- powers
regexRust crate- powers
Rust,rg(ripgrep) - https://github.com/rust-lang/regex
- powers
ReDOS
- Regex Denial of Service
- OWASP: https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS
- Cloudflare outage due to RegEx: https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/
Major Features of Regex Engines
- Character classes
- Negated Character classes
- Character class range
- Shorthands
- Unicode Properties
- POSIX character classes
- Dot
- Anchors
- Word Boundaries
- Alternation
- Quantifier
- Non-greedy quantifier
- Look around
- Look ahead
- Look behind
- Named capture and Backreferences
- Atomic grouping
- Conditionals
- Comments
Unicode character classes
- aka Unicode Property escapes or Unicode Character property
- https://en.wikipedia.org/wiki/Unicode_character_property
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape
- https://unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt
- Every Unicode character has a set of properties that describe it
- This info can be accessed via unicode database (UCD)
- https://codepoints.net/ can be used and shows all properties under “Complete Record”
unicodecommand line also gives this info, although it is less technical
ahas:General_Category=Lowercase_letterScript=Latn
- Categories are hierarchical in nature
- Main category use 1-Letter (
L= Letter,N= Number) - Sub category use 2-letter (
Ll= Lowercase Letter,Nd= Decimal Number) - Matching main category automatically targets all sub-categories
- Main category use 1-Letter (
- Syntax:
\p{Property_Key=Value}\p{Value}whereProperty_Key=General_Category\p{Property_Key}whereProperty_Keyis Binary
- Examples
\p{L}— matches letter (implicitGeneral_Category)\p{Lu}— matches upper case letter (implicitGeneral_Category)\p{Script=Deva}— matches Devanagari characters\p{Emoji}— matches emojis (Binary Property)\P{Emoji}— matches characters which are not emojis (Binary Property)
- Example Regex
- Text:
Chloé smiled as she typed her name into the form! - Regex:
^\p{L}+(^\w+may fail in some engines because of presence ofé) - Match:
Chloé
- Text:
General_Category
- alias:
gc,Category - Major Categories and Sub categories are shown below
| Parent Value (Short) | Child Value (Short) | Description & Examples |
|---|---|---|
Letter (L) | Matches any letter in any global alphabet | |
Uppercase_Letter (Lu) | Capital letters Examples: A, Δ | |
Lowercase_Letter (Ll) | Small letters Examples: a, λ | |
Titlecase_Letter (Lt) | Ligatures printed at the start of words Examples: Dž | |
Modifier_Letter (Lm) | Spacing modifier letters Examples: ʰ | |
Other_Letter (Lo) | Ideographs with no case distinction Examples: 书 (Chinese), و (Arabic) | |
Number (N) | Matches any numerical symbol | |
Decimal_Number (Nd) | Standard digits used for math Examples: 0-9, 𝟟 | |
Letter_Number (Nl) | Numerals composed of letters Examples: Ⅵ (Roman numeral) | |
Other_Number (No) | Fractions, superscripts, subscripts Examples: ½, ³ | |
Punctuation (P) | Matches all typographic punctuation markers | |
Dash_Punctuation (Pd) | Hyphens and dashes Examples: -, — | |
Open_Punctuation (Ps) | Opening brackets Examples: (, [, { | |
Close_Punctuation (Pe) | Closing brackets Examples: ), ], } | |
Symbol (S) | Matches math, currency, or technical signs | |
Math_Symbol (Sm) | Mathematical syntax operators Examples: +, =, ∞ | |
Currency_Symbol (Sc) | Currency units Examples: $, €, ₹ | |
Separator (Z) | Matches spaces and hidden layout breaks | |
Space_Separator (Zs) | Standard horizontal graphic spaces Examples: U+0020 (Standard Space), U+00A0 (No break space, same as  ) | |
Mark (M) | Combined character accents and text modifiers | |
Nonspacing_Mark (Mn) | Accents that sit over letters without widening text width Example: ◌́ (Combining Acute Accent) | |
Spacing_Mark (Mc) | Diacritics that expand letter width layout dynamically Example: ◌ा (Hindi vowel marker) | |
Other (C) | Matches structural system flags, legacy codes, and code points | |
Control (Cc) | Legacy ASCII commands and device signal codes Examples: \n, \r, \t | |
Format (Cf) | Hidden script direction layout controls Examples: U+200E (Left-to-Right Mark), U+200F (Right-to-Left Mark) |
Scripts
Script- alias:
sc
- alias:
Script_Extensions- alias:
scx
- alias:
| Value (Short) | Description & Examples |
|---|---|
Latin (Latn) | Western European alphabets |
Han (Hani) | Chinese Hanzi and Japanese Kanji characters |
Cyrillic (Cyrl) | Slavic alphabets (e.g., Б, я) |
Greek (Grek) | Greek text and math symbols (e.g., π, Ω) |
Hiragana (Hira) | Japanese phonetic Hiragana |
Katakana (Kana) | Japanese phonetic Katkana |
Devanagari (Deva) | Hindi, Marathi, and Sanskrit script |
Binary
EmojiWhitespaceHex_digit