Reputation: 97
I am very new to regex. I am trying to read a log file line by line.And trying to find patterns like below, they can be anywhere on the line , not just the starting.
18514&[email protected]"qwqw (need to extract only [email protected])
"emailTo":"[email protected]"
pseId="12121212ffsd"
how can i use re.search to search for all three patterns together ?
Upvotes: 0
Views: 278
Reputation:
Here is a solution. I hope, it extracts the e-mail address you want.
I could not create a more accurate regex expression, because you did not provide more information about the logfile. Also I am not sure, if I understand your question right.
import re
for line in open('filename', 'r'):
firstPattern = re.search(r'email=(.*?)"', line)
secondPattern = re.search(r'"emailTo":"(.*?)"', line)
thirdPattern = re.search(r'pseId="(.*?)"', line)
if firstPattern:
print(firstPattern.group(1))
elif secondPattern:
print(secondPattern.group(1))
elif thirdPattern:
print(thirdPattern.group(1))
Upvotes: 2