import re
regex = re.compile(r".*((https?)://(www\.)?twitter\.com/[^.\s]+)")
test_str = ("[15:47] <bb> I'm just going to keep them coming https://twitter.com/sarahbryant_/status/791002091045130240?lang=en\n"
"[15:49] <zz> hmmmmmm test https://twitter.com/randygdub/status/525142857015762944?lang=en\n"
"[15:49] <zz> https://twitter.com/sarahbryant_/status/791002091045130240?lang=en\n"
"[15:49] <aa> Tweet: I just found this on someone's car....\n"
"[15:52] <zz> https://twitter.com/sarahbryant_/status/791002091045130240?lang=en test 3\n"
"[15:52] <aa> Tweet: I just found this on someone's car....\n"
"[15:52] <zz> test4 pls test https://twitter.com/sarahbryant_/status/791002091045130240?lang=en test 3((https?)://(www\\.)?twitter\\.com/[^.\\s]+)")
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