kent at kentsjohnson.com
Sat May 6 16:17:46 CEST 2006
> I have a string...
> str = "tyrtrbd =ffgtyuf == =tyryr =u=p ttttff"
> I want to replace the characters after each '=',
If you are replacing any char after = with # then re.sub() makes it easy:
In : import re
In : s = "tyrtrbd =ffgtyuf == =tyryr =u=p ttttff"
In : re.sub('=.', '=#', s)
Out: 'tyrtrbd =#fgtyuf =# =#yryr =#=# ttttff'
If the replacement char is not fixed then make the second argument to
re.sub() be a callable that computes the replacement.
PS str is not a good name for a string, it shadows the built-in str.
More information about the Python-list