import re
regex = re.compile(r"https?://([\w+\-\.]+)", flags=re.MULTILINE)
test_str = (" 'https://www.amazon.com/Technology-Ventures-Enterprise-Thomas-Byers/dp/0073523429',\n"
" 'http://www.interactivedynamicvideo.com/',\n"
" 'http://www.nytimes.com/2007/11/07/movies/07stein.html?_r=0',\n"
" 'http://evonomics.com/advertising-cannot-maintain-internet-heres-solution/',\n"
" 'http://github.com/keppel/pinn',\n"
" 'http://phys.org/news/2015-09-scale-solar-youve.html',\n"
" 'https://iot.seeed.cc',\n"
" 'http://www.bfilipek.com/2016/04/custom-deleters-for-c-smart-pointers.html',\n"
" 'http://beta.crowdfireapp.com/?beta=agnipath',\n"
" 'https://www.valid.ly?param',\n"
" 'http://css-cursor.techstream.org'")
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