regexp substitution - a lot of work!

Lukas Holcik xholcik1 at fi.muni.cz
Wed Jun 16 10:21:34 EDT 2004


 	Hi Python crazies!:))
There is a problem to be solved. I have a text and I have to parse 
it using a lot of regular expressions. In (lin)u(ni)x I could write in 
bash:

 	cat file | sed 's/../../' | sed 's/../../' .. .. .. > parsed_file

I write a parser in python and what I must do is:

 	regexp = re.compile(..)
 	result = regexp.search(data)
 	while result:
 		data = data[:result.start()] + .. result.group(..) + \
 			data[result.end():]
 		result = regexp.search(data)

 	... for one regexp substitution

 	instead of just: s/../../

That is quite a lot of work! Don't you know some better and easier way? 
Thanks in advance,

---------------------------------------_.)--
|  Lukas Holcik (xholcik1 at fi.muni.cz)  (\=)*
----------------------------------------''--



More information about the Python-list mailing list