regex
Alternative regular expression module, to replace re.
This package has a good security score with no known vulnerabilities.
Community Reviews
Powerful re replacement with fuzzy matching, but migration requires careful testing
The fuzzy matching capability (`regex.search(r'(hello){e<=2}', text)`) is genuinely useful for real-world text processing where you need approximate matches. The improved Unicode support with `\p{...}` properties saves countless hours compared to manually constructing character classes. However, the lack of type stubs means losing IDE autocomplete benefits, and you'll need to rely on docstrings and documentation.
Error messages are generally clear and often more helpful than stdlib re, particularly for complex patterns. The documentation is comprehensive but can feel overwhelming—it assumes familiarity with advanced regex concepts. Performance is comparable to re for standard patterns, though complex features naturally add overhead.
Best for: Projects requiring fuzzy text matching, complex Unicode handling, or advanced regex features beyond what stdlib re provides.
Avoid if: You need strong TypeScript-style typing support or only use basic regex patterns where stdlib re suffices.
Drop-in re replacement with superior features, minimal production concerns
From an operations standpoint, it's refreshingly boring in a good way. No connection pools to tune, no retry logic needed, no breaking API changes in years. Pattern compilation is slightly slower than re, so pre-compile and cache your patterns—this is standard practice anyway. The timeout parameter on matching operations is crucial for production; we set conservative defaults (100ms) to prevent catastrophic backtracking from user-supplied patterns.
One gotcha: error messages for malformed patterns are more verbose than re, which helps debugging but can expose implementation details in logs. We wrap pattern compilation in try/except blocks with sanitized error messages for user-facing services.
Best for: Production services needing robust regex with Unicode support, timeout protection, and advanced features beyond stdlib re.
Avoid if: You're doing trivial string matching where str methods suffice or need absolute minimal dependencies.
Drop-in re replacement with better Unicode handling and useful extensions
From a security perspective, it's generally solid. The module doesn't introduce new attack surfaces beyond what re already presents, and the developer has been responsive to security issues. The main concern is ReDoS (Regular Expression Denial of Service) vulnerabilities, but that's inherent to regex engines generally. Error messages are informative without leaking system details, and there's no special authentication or network concerns since it's purely computational.
One practical consideration: it's a C extension with no pure Python fallback, so you're adding a compiled dependency to your supply chain. Updates have been consistent, and CVE response has been reasonable when issues arise. The API compatibility with re means migration is typically painless, though subtle behavioral differences exist around Unicode boundaries.
Best for: Projects requiring robust Unicode text validation, international character class matching, or advanced regex features beyond standard re capabilities.
Avoid if: You need a pure Python solution for portability or your patterns work fine with the stdlib re module.
Sign in to write a review
Sign In