import re
regex = re.compile(r"REGISTER sip:(?<your_field>(.|\n)+)User-Agent:", flags=re.MULTILINE)
test_str = ("03:25:17.296: SIPTR: Received [0,UDP] 543 bytes from 10.xx.7x.1xx:8080 <<<<<\n"
"REGISTER sip:10.xx.7x.1xx SIP/2.0\n"
"Via: SIP/2.0/UDP 10.xx.7x.1xx;branch=hkhi8u09uj\n"
"From: \"Dummy\" ;tag=78979uh\n"
"CSeq: 68789 REGISTER\n"
"Call-ID: xxxxxx-7689-xxxx@10.xx.7x.1xx\n"
"Contact: ;methods=\"INVITE, ACK, BYE, CANCEL, OPTIONS, UPDATE, REFER\"\n"
"User-Agent: Polycom_r64786r9879r87\n"
"Accept-Language: en\n"
"Max-Forwards: 70\n"
"Expires: 60")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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