Pattern-match & Replace - help required

Thomas Bach thbach at students.uni-mainz.de
Wed Dec 19 12:27:19 CET 2012


On Wed, Dec 19, 2012 at 02:42:26AM -0800, AT wrote:
> Hi,
> 
> I am new to python and web2py framework. Need urgent help to match a
> pattern in an string and replace the matched text.
> 

Well, what about str.replace then?

>>> 'egg, ham, tomato'.replace('ham', 'spam, ham, spam')
'egg, spam, ham, spam, tomato'


If the pattern you want to match is more complicated, have a look at
the re module!

Regards,
	Thomas.



More information about the Python-list mailing list