regex
ParsingAdvanced regex engine
What is regex?
The regex module is a drop-in replacement for Python's built-in re module, offering additional features including fuzzy matching (approximate string matching), variable-width lookbehinds, named capture groups with repeated captures, POSIX character classes, and atomic grouping.
regex is available in PyRun via micropip. It's particularly useful when you need to match patterns with slight typos (fuzzy matching), work with complex Unicode text, or use regex features that aren't supported in the standard re module.
Code Example
Named capture groups and fuzzy pattern matching.
Regex: Named Groups & Fuzzy
Try in Editorimport regex
# Named capture groups — parse a log line
log = "2025-07-04 14:32:01 ERROR [auth] Login failed for user@example.com"
pattern = r"(?P<date>\d{4}-\d{2}-\d{2}) (?P<time>\d{2}:\d{2}:\d{2}) (?P<level>\w+) \[(?P<module>\w+)\] (?P<message>.+)"
m = regex.match(pattern, log)
if m:
for k, v in m.groupdict().items():
print(f" {k:<10}: {v}")
# Fuzzy matching — find 'colour' with up to 1 error
print("\nFuzzy search (≤1 substitution):")
text = "I prefer colour and cilor and colouur"
for hit in regex.finditer(r"(?:colour){s<=1}", text):
print(f" found '{hit.group()}' at {hit.span()}")Why run regex in PyRun?
- ✦ Zero setup — no pip install, no virtual environment, no Python download
- ✦ Instant results — powered by WebAssembly, runs locally in your browser
- ✦ Share your code — generate a link and anyone can run it instantly
- ✦ Works offline — after first load, PyRun runs without internet