escape sequences and string comparisons
jkndeja at my-deja.com
jkndeja at my-deja.com
Tue Jan 9 04:17:59 EST 2001
Hi Remco, thanks for your reply:
>
> Simply using repr (or `` backquotes) gives the string as a string
literal,
> with the necessary things escaped. The only thing is that if there
are '
> quotes in the string, they aren't escaped, but instead "" quotes are
used
> to surround the string (and vice versa).
This doesn't really work for me - the 'necessary things' aren't the
ones I require:
>>> repr(']')
"']'"
whereas I'd want this character to be escaped "\]" in order to be used
within an RE.
For the moment I'm using my own version of re.escape(), which looks for
a set of characters and escapes them if found. It seems a little
inelegant though. My puzzle remains: My previous experience of REs
(from use in editors rather than, eg, P*RL) has led me to the heuristic
'it does no harm to escape a character; if the escaped form has no
special meaning, the backslash will be dropped'. Python doesn't seem to
follow this. I will investigate further...
Regards
Jon N
Sent via Deja.com
http://www.deja.com/
More information about the Python-list
mailing list