regex - How to parse this text file with regexp, in Python? -


i need parse text file contains logins , 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 use re, this:

import re fh = open('test1.txt') lines = fh.readlines() line in lines:         #print line         p = re.compile(r"|(.*?)|")         m2 = p.search(line)         if m2:                 print m2.group(0) 

the problem can't needed result! i've tried various combinations spaces , tabs, didn't work. solved split(), still want understand wrong. appreciated. thank you!

| special character in regular expressions "or"ing 2 expressions together. need escape \| match actual character. also, search() find 1 match. may want through other methods such findall.


Comments