Python re Module Studio
Python Regex Tester
Test regular expressions written for Python's standard re module, featuring named capture groups (?P<name>...), backreferences, and copy-ready Python code.
r""
Matches (3)re.finditer
INFO: Database connection established
groupdict():
level:"INFO"
message:"Database connection established"
WARN: Disk utilization exceeds 85%
groupdict():
level:"WARN"
message:"Disk utilization exceeds 85%"
ERROR: Connection refused on port 5432
groupdict():
level:"ERROR"
message:"Connection refused on port 5432"
re.sub() Preview
\g<name>[INFO] -> Database connection established [WARN] -> Disk utilization exceeds 85% [ERROR] -> Connection refused on port 5432
Python Code Generator
import re
# Compile Python regex with flags
pattern = re.compile(r"(?P<level>[A-Z]+):\s+(?P<message>.*)", re.MULTILINE)
text = """INFO: Database connection established
WARN: Disk utilization exceeds 85%
ERROR: Connection refused on port 5432"""
# Iterate through matches and extract groupdict
for match in pattern.finditer(text):
print("Match:", match.group(0))
print("Groups dict:", match.groupdict())
# Substitution using re.sub
result = pattern.sub(r"[\g<level>] -> \g<message>", text)
print("Substituted:", result)