I want to find two fixed patterns from a log file. Here is a line in a log file looks like
passed dangerb.xavier64.423181.k000.drmanhattan_resources.log Aug 23 04:19:37 84526 362
From this log, I want to extract drmanhattan
and 362
which is a number just before the line ends.
Here is what I have tried so far.
import sys
import re
with open("Xavier.txt") as f:
for line in f:
match1 = re.search(r'((\w+_\w+)|(\d+$))',line)
if match1:
print match1.groups()
However, everytime I run this script, I always get drmanhattan
as output and not drmanhattan 362
.
Is it because of |
sign?
How do I tell regex to catch this group and that group
?
I have already consulted this and this links however, it did not solve my problem.