import re
regex = re.compile(r"(url\s\d+[.]\d+[.]\d+[.]\d+[:](http|https|ftp).*)", flags=re.IGNORECASE)
test_str = ("URL 123.45.67.8:http://www.google-analytics.com/r/collect?v=1&_v=j41&a=1071188231&t=pageview&_s=1&dl=http%3A%2F%2Fm.sherdog.com%2F&ul=en-us&de=UTF-8&dt=Sherdog.com%3A%20UFC%2C%20Mixed%20Martial%20Arts%20(MMA)%20News%2C%20Results%2C%20Fighting&sd=32-bit&sr=320x480&vp=320x460&je=0&_utma=236548035.1293902652.1385044241.1442\n"
"URL 123.34.45.7:http://captive.apple.com/hotspot-detect.html")
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