I need to parse text file which contains logins and id of users
+----+---------------+---------------+
| Id | Login | Name |
+----+---------------+---------------+
| 1 | admin | admin |
| 2 | admin2 | admin2 |
| 3 | ekaterina | Ekaterina |
| 4 | commarik | commarik |
| 5 | basildrescher | BasilDrescher |
| 6 | danielalynn | DanielaLynn |
| 7 | rosez13yipfj | RoseZ13yipfj |
| 8 | veolanoyes | VeolaNoyes |
| 9 | angel | Angel |
| 10 | michalea44 | MichaleA44 |
+----+---------------+---------------+
So I use re
, like this:
import re
fh = open('test1.txt')
lines = fh.readlines()
for line in lines:
#print line
p = re.compile(r"|(.*?)|")
m2 = p.search(line)
if m2:
print m2.group(0)
The problem is that I can't get needed result! I've tried various combinations with spaces and tabs, but it didn't work. I solved this with split()
, but I still want to understand where I am wrong. Any help would be appreciated. Thank you!
p = re.compile(...)
could be outside thefor
loop.m2 = line.strip('|').split('|')
strip
andsplit
is probably the better solution here.