I am learning re module
for practice I have taken an export of my phone addressbook which is a comma seperated text file, containing
"First Name","Mobile Phone","Home Phone","Company","E-mail Address","Company Main Phone","Business Fax","Birthday"
as of now I am more interested in First name , mobile phone number and email address.
in my phone book I have first names with characters a-z in small caps as well as capitals with - and some also containig number or special characters so almost everything is included.
so I build a search pattern like this namePattern = re.compile('[a-zA-Z _@-]+')
this works fine but it also gets me all characters from company name, email address, birthday entries data what i need is to search the row containig First Name..similarly i want to seperate out email and number and so the search dont get mixed.
so far this is what I have got
ph=open(phile,"r")
try:
lines=ph.readlines()
firstLine=ph.readline()
except Exception as er:
print er
finally: ph.close()
print firstLine
namePattern = re.compile('[a-zA-Z _@-]+')
for index,line in enumerate(lines):
for namMatch in re.finditer(namePattern,line):
s=namMatch.start()
e=namMatch.end()
print index, line[s:e]
how should I only get First names only ...?