I am using RegEx to extract some data from a txt file. I've made the below for-loops to extract emails and birthdates and (tried) to append the outputs to a list. But when I print my list only the first appended output is printed. The birtdate RegEx works fine when run by itself. I'm sure I'm doing something very basic wrong.
f = open("/Users/me/Desktop/scrape.txt", "r", encoding="utf8")
list = []
for i in f:
if re.findall(r"((?i)[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.])", i):
list.append(i)
for k in f:
if re.findall(r'\d\d-\d\d-\d\d\d\d', k):
list.append(k)
print(list)
f.close()
(?i)in your first pattern. So you could get rid ofA-Z. Also in your second regex >\d\d\d\dis better written\d{4}fhas reached the end of file (EOF) already when you're entering the second loop. So you either need to dof.seek(0)before the second loop, or just|two regexes, I think piping two regexes should work just fine