import re
ip_reg = re.compile(r'(?:\d{1,3}\.){3}\d{1,3}')
print("--- IPS ---")
print(ip_reg.findall('\t\nSome text 127.0.0.1 GET ....\n4 127.0.0.2 8888 GET ....\n'))
print(ip_reg.findall(
'google.com has address 216.58.209.174\r\ngoogle.com mail is handled by 20 alt1.aspmx.l.google.com.'
))
print("\n --- Original domains: ---")
domain_reg = re.compile(r'(http[s]?://)([\w.]+)(.*)', re.U)
print(domain_reg.findall('http://a...content-available-to-author-only...k.com/user/56')[0][1])
print(domain_reg.findall('http://a...content-available-to-author-only...k.Com')[0][1])
print(domain_reg.findall('https://f...content-available-to-author-only...k.com')[0][1])
print(domain_reg.findall('https://s...content-available-to-author-only...e.com:8000/user/photo/56/')[0][1])
print(domain_reg.findall(u"http://дизайн.рф/какая-то-страница")[0][1])
def replace_domain(match):
# 0 - entire match
# 1 - ... - subgroups
return '{protocol}{domain}{url}'.format(protocol=match.group(1), domain='example.com', url=match.group(3))
print("\n --- Replaced domains ---")
print(domain_reg.sub(replace_domain, 'http://a...content-available-to-author-only...k.com/user/56'))
print(domain_reg.sub(replace_domain, 'http://a...content-available-to-author-only...k.Com'))
print(domain_reg.sub(replace_domain, 'https://f...content-available-to-author-only...k.com'))
print(domain_reg.sub(replace_domain, 'https://s...content-available-to-author-only...e.com:8000/user/photo/56/'))
print(domain_reg.sub(replace_domain, 'http://дизайн.рф'))
aW1wb3J0IHJlCgppcF9yZWcgPSByZS5jb21waWxlKHInKD86XGR7MSwzfVwuKXszfVxkezEsM30nKQpwcmludCgiLS0tIElQUyAtLS0iKQpwcmludChpcF9yZWcuZmluZGFsbCgnXHRcblNvbWUgdGV4dCAxMjcuMC4wLjEgR0VUIC4uLi5cbjQgMTI3LjAuMC4yIDg4ODggR0VUIC4uLi5cbicpKQpwcmludChpcF9yZWcuZmluZGFsbCgKICAgICdnb29nbGUuY29tIGhhcyBhZGRyZXNzIDIxNi41OC4yMDkuMTc0XHJcbmdvb2dsZS5jb20gbWFpbCBpcyBoYW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