Install & Compatibility
Where this runs
tested against v2026.7.19.20260720 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.098s · 20.5MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.3s · import 0.080s · 22MB
19MB installed
● package 19MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
regex
✓ import regex
The 'types-regex' package provides type hints for the 'regex' module; you import 'regex' itself.
Match
✓ from regex import Match
Import specific types like 'Match' directly from the 'regex' module.
Pattern
✓ from regex import Pattern
Import specific types like 'Pattern' directly from the 'regex' module.
This quickstart demonstrates how to use the `regex` library with type hints provided by `types-regex`. It shows compiling a regular expression pattern and then searching for it in a string, ensuring `Pattern` and `Match` objects are correctly typed.
import regex
from regex import Pattern, Match
def find_first_email(text: str) -> str | None:
# Compile the regex pattern with type annotation
email_pattern: Pattern[str] = regex.compile(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b")
# Search for the pattern in the text
match: Match[str] | None = email_pattern.search(text)
if match:
return match.group(0) # Return the entire matched string
return None
text_data = "Contact us at info@example.com or support@test.org for assistance."
first_email = find_first_email(text_data)
if first_email:
print(f"Found email: {first_email}")
else:
print("No email found.")
Debug
Known issues
gotchaThe `types-regex` package only provides type annotations. The actual `regex` runtime library must be installed separately alongside `types-regex` for your code to function at runtime.fixAlways install both packages: `pip install types-regex regex`.
affects: All versions of types-regex
gotchaThe versioning of `types-regex` (e.g., `X.Y.Z.YYYYMMDD`) indicates that it provides stubs for `regex` version `X.Y.Z` and was released on `YYYYMMDD`. Ensure that your installed `types-regex` version is compatible with your `regex` runtime library version to avoid type-checking errors.fixRefer to the `types-regex` PyPI page for the `regex` version it targets. Consider pinning both `regex` and `types-regex` versions in your `requirements.txt` (e.g., `regex==2026.4.4` and `types-regex==2026.4.4.20260408`) or using flexible version ranges, regularly updating and re-checking types.
affects: All versions
gotchaUpdates to type stubs, even minor ones, can sometimes introduce changes that cause existing code to fail type checking, especially if the underlying library's API has implicit changes not reflected in older stubs, or if stricter types are added.fixRegularly run your type checker (e.g., MyPy, Pyright) and review any new type errors. If an error is due to an intended API change, update your code. If it seems like an error in the stub, consider contributing a fix to the typeshed project.
affects: All versions
gotchaWhen defining regular expression patterns in Python, it's a best practice to use raw string notation (prefixing the string literal with `r`, e.g., `r"\d+"`). This prevents backslashes from being interpreted as Python escape sequences, which can lead to unexpected behavior or `SyntaxWarning` / `SyntaxError` with invalid escape sequences.fixAlways use raw strings for regex patterns, e.g., `regex.compile(r'\bword\b')` instead of `regex.compile('\bword\b')`. affects: All Python versions using `regex` or `re`
Upgrade
Version history
2026.7.19.20260720latest on PyPI · released Jul 20, 2026
Audit
Dependencies
regexrequiredThis package provides type stubs for the 'regex' runtime library, which must be installed separately to use its functionality.