RE Module How to escape $

Hans Nowak wurmy at
Sat Jun 8 17:35:32 CEST 2002

Prema wrote:
> Hi People !
> I'm trying to use the re.sub function to replace several instances of a
> PHP Variable eg "$Amount". Could someone please help with an example
> Thanks very much
> Mike


 >>> import re
 >>> s = "I have $amount dollars"
 >>> re.sub("\$\S+", "foo", s)
'I have foo dollars'


Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter::

More information about the Python-list mailing list