backslash in regular expression problem

Keith Murphy kpmurphy at my-deja.com
Fri Jun 30 16:21:33 EDT 2000


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?

Thanks,

	-->keith

In article <02de01bfd826$cf05bd80$6401a8c0 at home>,
  "Darrell Gallion" <darrell at dorb.com> wrote:
> Try to avoid assigning to "string" that will cause problems when you
import
> string
> Especially when your using "\" try to use raw strings. Note the
r"xxxx"
>
> >>> s=r"\END\\"
> >>> print re.sub('[\\\]','',s)
> END
> >>> print re.sub(r'[\\]','',s)
> END
>
> --Darrell Gallion
>
> ----- Original Message -----
> From: "Gordon McLeod" <Gordon.McLeod at wolfson.co.uk>
> > import re
> > string="\END\\"
> > x=re.sub('[\]','',string)
> > print x
> >
> > and expect x to be 'END' but I get:
> >
> > Traceback (innermost last):
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list