backslash in regular expression problem
Keith Murphy
kpmurphy at my-deja.com
Wed Jul 5 10:35:39 EDT 2000
how does re.escape help?
>>> str = '\\\hi'
>>> str
'\\\\hi'
>>> print str
\\hi
>>> import re
>>> x = re.escape(str)
>>> x
'\\\\\\\\hi'
>>> print x
\\\\hi
>>>
i want to display the actual string, and also be able to write it to a
file... thanks,
keith
In article <m3g0pu7kix.fsf at atrus.jesus.cam.ac.uk>,
Michael Hudson <mwh21 at cam.ac.uk> wrote:
> Keith Murphy <kpmurphy at my-deja.com> writes:
>
> > what if instead of having '\\stuff' you have a str = '\\stuff' ?
> >
> > i know that you can print r'\\stuff' but you can't print rstr...
> >
> > how do you use the raw with a variable?
>
> You don't. You do know about re.escape? Asking that question
> suggests you might not...
>
> Cheers,
> M.
>
> --
> I saw `cout' being shifted "Hello world" times to the left and
> stopped right there. -- Steve Gonedes
>
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list