regex
Enhanced regular expression library for Python — drop-in replacement for the re module with additional features. regex features: fuzzy matching (BESTMATCH/ENHANCEMATCH flags for approximate matching), variable-length lookbehind, atomic groups for backtracking control, possessive quantifiers, (*SKIP)(*FAIL) verbs, branch reset groups, Unicode properties (\p{Letter}), named character classes, set operations on character classes, full Python re API compatibility, scoped inline flags, \K (keep) operator, and fixed bugs in re module. Compatible with re.compile() interface while adding ~30 new features.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Regex library. User-controlled patterns: even with atomic groups, malicious patterns can be slow — validate or sandbox user-supplied patterns. Fuzzy matching with high error tolerance is quadratic — limit {e<=} values for untrusted input. No network calls.
⚡ Reliability
Best When
Complex regex patterns requiring Unicode properties, fuzzy matching, variable lookbehind, or atomic groups — regex provides what re lacks while maintaining full API compatibility.
Avoid When
Simple patterns (use stdlib re), grammar-based parsing (use lark/pyparsing), or when the extra dependency isn't justified by the features needed.
Use Cases
- • Agent fuzzy matching — import regex; pattern = regex.compile(r'(?:hello){e<=1}', regex.BESTMATCH); m = pattern.search('helo world') — fuzzy match; agent finds approximate matches allowing 1 edit error (insertion/deletion/substitution); BESTMATCH finds fewest errors; useful for typo-tolerant search
- • Agent Unicode property matching — import regex; pattern = regex.compile(r'\p{Letter}+'); words = pattern.findall('Hello 世界 мир') — Unicode; agent extracts words across all scripts using Unicode property classes; \p{Letter} matches letters in any Unicode block; more powerful than \w for multilingual text
- • Agent variable-length lookbehind — import regex; pattern = regex.compile(r'(?<=\w{2,10})@'); matches = pattern.findall(text) — variable lookbehind; agent uses variable-length lookbehind assertions; re module requires fixed-length lookbehind; regex allows patterns like (?<=\d{1,5}) for flexible lookbehind
- • Agent atomic group backtracking — import regex; pattern = regex.compile(r'(?>\d+)px'); m = pattern.match('12345px') — atomic group; agent uses atomic groups to prevent catastrophic backtracking; (?>...) prevents backtracking into group; critical for ReDoS prevention in user-controlled input patterns
- • Agent drop-in re replacement — import regex as re; pattern = re.compile(r'(\w+)', re.UNICODE | re.VERSION1); for m in pattern.finditer(text): process(m.group(1)) — drop-in; agent replaces import re with import regex as re; existing code works unchanged with additional features available; regex.VERSION1 enables new features
Not For
- • Simple patterns — for basic regex without advanced features, Python's built-in re module is sufficient and requires no extra dependency
- • Structured parsing — for grammar-based parsing use pyparsing or lark; complex regex patterns become unmaintainable
- • Performance-critical hot loops — regex C extension is fast but adds import overhead; for the highest performance use re with simple patterns
Interface
Authentication
No auth — pure Python/C extension library.
Pricing
regex is Apache 2.0 licensed. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ VERSION1 vs VERSION0 differences — regex.VERSION0 is backward-compatible with re module; regex.VERSION1 enables new features like set operations, atomic groups, and possessive quantifiers; some VERSION0 patterns behave differently in VERSION1; agent code mixing features should use explicit regex.VERSION1 flag; default may differ by regex version
- ⚠ Fuzzy matching {e<=1} syntax requires understanding of edit types — {e<=1} allows 1 error of any type (insert/delete/substitute); {s<=1,i<=1,d<=1} allows specific error types; BESTMATCH flag finds fewest errors; ENHANCEMATCH prefers fewest errors at best position; agent code needing spell-check style matching must understand error type parameters
- ⚠ \p{} Unicode properties require regex not re — \p{Letter}, \p{Digit}, \p{Script=Latin} only work with regex module; re module raises re.error for \p; agent code switching from re to regex for Unicode: import regex as re at module level; regex is drop-in replacement but import statement must change
- ⚠ Possessive quantifiers prevent backtracking entirely — pattern \d++ (possessive) never releases captured digits; unlike atomic group, possessive works at quantifier level; agent code using possessive quantifiers for performance must verify the pattern still matches intended input — possessive can cause no-match where non-possessive succeeds
- ⚠ Timeout parameter not available like in re.timeout workarounds — regex module doesn't have native timeout; for ReDoS-safe patterns with user input: use atomic groups and possessive quantifiers to prevent catastrophic backtracking; or run in separate process with timeout; agent code processing untrusted patterns should validate pattern complexity
- ⚠ Compiled patterns with VERSION1 not compatible with re — regex.compile(pattern, regex.VERSION1) returns regex Pattern not re.Pattern; isinstance(p, re.Pattern) is False; agent code passing compiled patterns to third-party libraries expecting re.Pattern must use re.compile or VERSION0; check library compatibility before switching
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for regex.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-06.