regexp substitution - a lot of work!

Eddie Corns eddie at
Wed Jun 16 17:12:27 CEST 2004

Lukas Holcik <xholcik1 at> writes:

> 	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 

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

In Unix you would actually do:

  $ sed 's/pat1/rep1/ s/pat2/rep2/ ...' <infile >outfile

to do the replacements in one pass.  (you will now anyway :)

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

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

> 	... 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,


More information about the Python-list mailing list