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.
import 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
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Regex
Master Regular Expressions (Regex) in Python. Learn to search, match, split, and substitute string data using the built-in re library.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python Regex Patterns (re module)
Reference guide for Python regular expressions. Learn match, search, findall, sub, and essential regex patterns.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.