escape sequences and string comparisons
Remco Gerlich
scarblac at pino.selwerd.nl
Wed Jan 10 12:17:26 EST 2001
jkndeja at my-deja.com <jkndeja at my-deja.com> wrote in comp.lang.python:
> OK, perhaps I shouldn't have written 'RE' match above. What I was
> hoping/expecting is that this:
>
> >>> import re
> >>> s = r'[123]'
> >>> r = re.escape(s)
> >>> r
> '\\[123\\]'
> >>> r == s
> 0
> >>>
>
> or something similar, would give 1, not zero
But *why*? They're two different strings. You have a string that
contains the characters '[]', which are special in regexen. Then you
ask it to escape all the special regex characters. And then you want the
result to be not escaped?!
I am really confused now.
--
Remco Gerlich
More information about the Python-list
mailing list