import re
regex = re.compile(r"(\d{5})[-. ](\d{6})", flags=re.MULTILINE)
test_str = ("something 01234 567890 around\n"
"aaa 01111-222111 bbbb\n"
"cccc 09876.543210 ddd\n")
subst = "(one:\\1) (two:\\2) (three:3)"
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html