Advertisement
bacnguyenxgen

Untitled

Jul 21st, 2022
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import re
  2.  
  3. regex = re.compile(("([a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`"
  4.                     "{|}~-]+)*(@|\sat\s)(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(\.|"
  5.                     "\sdot\s))+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)"))
  6.  
  7. bkav = open("bkav.txt", "r", encoding='utf-8').read()
  8.  
  9. def get_emails(s):
  10.     """Returns an iterator of matched emails found in string s."""
  11.     # Removing lines that start with '//' because the regular expression
  12.     # mistakenly matches patterns like 'http://foo@bar.com' as '//foo@bar.com'.
  13.     return (email[0] for email in re.findall(regex, s) if not email[0].startswith('//'))
  14.  
  15. h = open("bkav3.txt","w", encoding='utf-8')
  16. for a in get_emails(bkav):
  17.     print(a)
  18.     h.write(a)
  19.  
  20.  
  21. h.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement