regex substitution question

Eric Arnold umopi at psyon.org
Fri Jul 19 03:00:24 EDT 2002


I have a question about a regex substitution.  Lets say that with the
following string:

x11111x22222x33333x44444x

I wanted to find anything that looked like this: 'x([^x]*)x[^x]*x' and
replace only the first group with something (say "-")
so the first match would be:
"x(11111)x22222x"
which would change the line to:
x-x22222x33333x44444x

and so on ... then the last match would be:
"x(33333)x44444x"
which would change the line to:
x-x-x-x44444x

but the last "44444" would never get substituted.  What would be the easiest
way to accomplish this?

Thanks!
Eric






More information about the Python-list mailing list