regex question

proctor 12cc104 at gmail.com
Mon Jan 8 03:28:42 EST 2007


Steven D'Aprano wrote:
> On Sun, 07 Jan 2007 23:57:00 -0800, proctor wrote:
>
> > it does work now...however, one more question:  when i type:
> >
> > rx_a = re.compile(r'a|b|c')
> > it works correctly!
> >
> > shouldn't:
> > rx_a = re.compile(makeRE(test))
> > give the same result since makeRE(test)) returns the string "r'a|b|c'"
>
> Those two strings are NOT the same.
>
> >>> s1 = r'a|b|c'
> >>> s2 = "r'a|b|c'"
> >>> print s1, len(s1)
> a|b|c 5
> >>> print s2, len(s2)
> r'a|b|c' 8
>
> A string with a leading r *outside* the quotation marks is a raw-string.
> The r is not part of the string, but part of the delimiter.
>
> A string with a leading r *inside* the quotation marks is just a string
> with a leading r. It has no special meaning.
>
>
>
> --
> Steven D'Aprano

thanks steven,

is there any way i would be successful then, in using raw string inside
my makeRE() function?

proctor.




More information about the Python-list mailing list