import re
regex = re.compile(r"(?P<HostName>(?<=\),).*?(?=,.?Default))", flags=re.MULTILINE | re.IGNORECASE)
test_str = ("\"2018-12-12 13:25:30\",\"Renju, Jacob,M(renjutest)\",\"Renju, Jacob, M (rtest),Renju123,Default Site,Test/firewall\",\"10.221.5.136\",\"XXX.XXX.XXX.XXX\",\"Allowed\",\"16 (A)\",\"NOERROR\",\"1XX.1X.1XX.1XX.Test.com.\",\"Computer Security\"\n\n\n"
"\"2018-12-12 13:09:55\",\"rtest\",\"Renju123,Default Site,Renju Renju/Renju\",\"10.250.33.85\",\"XXX.XXX.XXX.XXX\",\"Allowed\",\"12 (PTR)\",\"NOERROR\",\"1XX.1X.1XX.1XX.Test.com.\",\"Software/Technology\"")
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