0
pull just email address from list
Hello everyone, I'm trying to write a script that pulls only email addresses from a list and places them into a new list. My list looks like this: firstname lastname <email@email.com>, firstname lastname <email@email.com>, etc. I can't think of how to append starting after a certain character "<" and stop once a certain character is reached ">". and then continue this until the end of the list is reached. Appreciate any help Thanks, David
2 Réponses
+ 6
You can use regex
import re
a=["firstname lastname <email@email.com>", "firstname lastname <email@email.com>"]
for i in a:
print(re.findall("<(.*)>",i))
.* returns one or more occurrences of characters between < and > and brackets around it returns only that particular text instead of returning < and > as well
0
Abhay thanks so much for answering! it works!