Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...<name@domain.com>...
- >>> import re
- >>> line = "should we use regex more often? let me know at 321dsasdsa@dasdsa.com.lol"
- >>> match = re.search(r'[w.-]+@[w.-]+', line)
- >>> match.group(0)
- '321dsasdsa@dasdsa.com.lol'
- >>> line = "why people don't know what regex are? let me know 321dsasdsa@dasdsa.com.lol dssdadsa dadaads@dsdds.com"
- >>> match = re.findall(r'[w.-]+@[w.-]+', line)
- >>> match
- ['321dsasdsa@dasdsa.com.lol', 'dadaads@dsdds.com']
- >>> import re
- >>> text = "this is an email la@test.com, it will be matched, x@y.com will not, and test@test.com will"
- >>> match = re.findall(r'[w-._+%]+@test.com',text) # replace test.com with the domain you're looking for, adding a backslash before periods
- >>> match
- ['la@test.com', 'test@test.com']
- import re
- line = "why people don't know what regex are? let me know asdfal2@als.com, Users1@gmail.de "
- "Dariush@dasd-asasdsa.com.lo,Dariush.lastName@someDomain.com"
- match = re.findall(r'[w.-]+@[w.-]+', line)
- for i in match:
- print(i)
- print(match)
- text = "blabla <hello@world.com>><123@123.at> <huhu@fake> bla bla <myname@some-domain.pt>"
- # 1. find all potential email addresses (note: < inside <> is a problem)
- matches = re.findall('<S+?>', text) # ['<hello@world.com>', '<123@123.at>', '<huhu@fake>', '<myname@somedomain.edu>']
- # 2. apply email regex pattern to string inside <>
- 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]) ]
- print emails # ['hello@world.com', '123@123.at', 'myname@some-domain.pt']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement