emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unquoted special characters in regexps


From: Luc Teirlinck
Subject: Re: Unquoted special characters in regexps
Date: Fri, 3 Mar 2006 17:48:25 -0600 (CST)

Martin Rudalics wrote:

   The question whether writing '\\' before the `]' is relevant for the
   example cited above.  Usually, when I see a `\\]' outside a character
   alternative I expect it to match a right bracket in some text.  And,
   usually, in that text a left bracket will precede the right bracket.
   Hence, if in the text above the author had used `\\]' instead of `\]' it
   would have been easy to conclude - from the absence of a preceding `\\['
   - that something went wrong.  Vice versa, when seeing a `\\[' I usually
   expect it to have a corresponding `\\]' somehwere on the right.

I believe that you make understanding regexps hard on yourself by
making all kind of assumptions that often are not satisfied.

There is no reason why a literal `]' should be matched by a literal
`[' to the right or vice versa.  Even _if_ the `[' and the `]' balance
in the text you are parsing through _considered in its entirety_
(which is not at all guaranteed), you might be inside, say, a nested
Lisp vector and your regexp may be searching for its end.  No balance
of literal `[' and `]' at all.  This is _not_ an exceptional
situation.  It occurs all over the place in the Emacs source code.

Sincerely,

Luc.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]