SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 835 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ...<name@domain.com>...
  2.    
  3. >>> import re
  4. >>> line = "should we use regex more often? let me know at  321dsasdsa@dasdsa.com.lol"
  5. >>> match = re.search(r'[w.-]+@[w.-]+', line)
  6. >>> match.group(0)
  7. '321dsasdsa@dasdsa.com.lol'
  8.    
  9. >>> line = "why people don't know what regex are? let me know 321dsasdsa@dasdsa.com.lol   dssdadsa dadaads@dsdds.com"
  10. >>> match = re.findall(r'[w.-]+@[w.-]+', line)
  11. >>> match
  12. ['321dsasdsa@dasdsa.com.lol', 'dadaads@dsdds.com']
  13.    
  14. >>> import re
  15. >>> text = "this is an email la@test.com, it will be matched, x@y.com will not, and test@test.com will"
  16. >>> match = re.findall(r'[w-._+%]+@test.com',text) # replace test.com with the domain you're looking for, adding a backslash before periods
  17. >>> match
  18. ['la@test.com', 'test@test.com']
  19.    
  20. import re
  21. line = "why people don't know what regex are? let me know asdfal2@als.com, Users1@gmail.de "
  22.        "Dariush@dasd-asasdsa.com.lo,Dariush.lastName@someDomain.com"
  23. match = re.findall(r'[w.-]+@[w.-]+', line)
  24. for i in match:
  25.     print(i)
  26.    
  27. print(match)
  28.    
  29. text = "blabla <hello@world.com>><123@123.at> <huhu@fake> bla bla <myname@some-domain.pt>"
  30.  
  31. # 1. find all potential email addresses (note: < inside <> is a problem)
  32. matches = re.findall('<S+?>', text)  # ['<hello@world.com>', '<123@123.at>', '<huhu@fake>', '<myname@somedomain.edu>']
  33.  
  34. # 2. apply email regex pattern to string inside <>
  35. emails = [ x[1:-1] for x in matches if re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$)", x[1:-1]) ]
  36. print emails   # ['hello@world.com', '123@123.at', 'myname@some-domain.pt']
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top