RE Module How to escape $

Hans Nowak wurmy at earthlink.net
Sat Jun 8 11:35:32 EDT 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

Sure...

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

HTH,

-- 
Hans (base64.decodestring('d3VybXlAZWFydGhsaW5rLm5ldA=='))
# decode for email address ;-)
The Pythonic Quarter:: http://www.awaretek.com/nowak/




More information about the Python-list mailing list