import re
regex = re.compile(r"http://(www\.)?(schema\.org|stackoverflow\.com|opensource\.org|php\.net|(?:[a-zA-Z]{2}\.)?wikipedia\.org|fsf\.org|creativecommons\.org|github\.com|getbootstrap\.com|mozilla\.org|firefox\.com|opera\.com|google\.com|bing\.com|yahoo\.com|apple\.com|microsoft\.com)", flags=re.MULTILINE | re.IGNORECASE)
test_str = ("http://schema.org/\n"
"http://getbootstrap.com/\n"
"http://github.com/\n\n"
"http://wikipedia.org\n"
"http://www.wikipedia.org\n"
"http://en.wikipedia.org")
subst = "https://\\1\\2"
result = regex.sub(subst, test_str)
if result:
print(result)
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