fork download
  1. import re
  2.  
  3. ip_reg = re.compile(r'(?:\d{1,3}\.){3}\d{1,3}')
  4. print("--- IPS ---")
  5. print(ip_reg.findall('\t\nSome text 127.0.0.1 GET ....\n4 127.0.0.2 8888 GET ....\n'))
  6. print(ip_reg.findall(
  7. 'google.com has address 216.58.209.174\r\ngoogle.com mail is handled by 20 alt1.aspmx.l.google.com.'
  8. ))
  9.  
  10. print("\n --- Original domains: ---")
  11. domain_reg = re.compile(r'(http[s]?://)([\w.]+)(.*)', re.U)
  12. print(domain_reg.findall('http://a...content-available-to-author-only...k.com/user/56')[0][1])
  13. print(domain_reg.findall('http://a...content-available-to-author-only...k.Com')[0][1])
  14. print(domain_reg.findall('https://f...content-available-to-author-only...k.com')[0][1])
  15. print(domain_reg.findall('https://s...content-available-to-author-only...e.com:8000/user/photo/56/')[0][1])
  16. print(domain_reg.findall(u"http://дизайн.рф/какая-то-страница")[0][1])
  17.  
  18.  
  19. def replace_domain(match):
  20. # 0 - entire match
  21. # 1 - ... - subgroups
  22. return '{protocol}{domain}{url}'.format(protocol=match.group(1), domain='example.com', url=match.group(3))
  23.  
  24. print("\n --- Replaced domains ---")
  25. print(domain_reg.sub(replace_domain, 'http://a...content-available-to-author-only...k.com/user/56'))
  26. print(domain_reg.sub(replace_domain, 'http://a...content-available-to-author-only...k.Com'))
  27. print(domain_reg.sub(replace_domain, 'https://f...content-available-to-author-only...k.com'))
  28. print(domain_reg.sub(replace_domain, 'https://s...content-available-to-author-only...e.com:8000/user/photo/56/'))
  29. print(domain_reg.sub(replace_domain, 'http://дизайн.рф'))
Success #stdin #stdout 0.02s 9992KB
stdin
Standard input is empty
stdout
--- IPS ---
['127.0.0.1', '127.0.0.2']
['216.58.209.174']

 --- Original domains: ---
a...content
a...content
f...content
s...content
дизайн.рф

 --- Replaced domains ---
http://e...content-available-to-author-only...k.com/user/56
http://e...content-available-to-author-only...k.Com
https://e...content-available-to-author-only...k.com
https://e...content-available-to-author-only...e.com:8000/user/photo/56/
http://e...content-available-to-author-only...e.com