import re
regex = re.compile(r"(?:^|,)([A-Za-z\-]+?)(?::[A-Z\-]+)?=(\".+?\"|\d+?)(?=,|$)", flags=re.MULTILINE)
test_str = "EXT-X-DATERANGE:ID=\"PreRoll_Ident_Open\",START-DATE=\"2016-12-14T120000.000z\",DURATION=3,X-PlayHeadStart=\"0.000\",X-AdID=\"AA-1QPN49M9H2112\",X-TRANSACTION-VPRN-ID=\"1486060788\",X-TrackingDefault=\"1\",X-TrackingDefaultURI=\"http,//606ca.v.fwmrm.net/ad/l/1?s=g015&n=394953%3B394953&t=1485791181366184015&f=&r=394953&adid=15914070&reid=5469372&arid=0&auid=&cn=defaultImpression&et=i&_cc=15914070,5469372,,,1485791181,1&tpos=0&iw=&uxnw=394953&uxss=sg579054&uxct=4&metr=1031&init=1&vcid2=394953%3A466c5842-0cce-4a16-9f8b-a428e479b875&cr=\"s=0&iw=&uxnw=394953&uxss=sg579054&uxct=4&metr=1031&init=1&vcid2=394953%3A466c5842-0cce-4a16-9f8b-a428e479b875&cr=\""
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