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: martin rudalics
Subject: Re: Unquoted special characters in regexps
Date: Sun, 26 Feb 2006 14:13:49 +0100
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

> Martin Rudalics wrote:
>
>    `]' is _also_ special in a character alternative, like `^'.  `-' is
>    special _only_ in a character alternative.
>
> I may be overlooking something, but _which_ special meaning does `]'
> have outside of character alternatives?

That of closing a character alternative.  When you write

(defvar foo "]")
(defvar bar "\\]")

you can't interchangeably use `foo' and `bar' in an arbitrary regular
expression.  Some people call this "referential transparency".

> You are using \\] to quote `]'.  Could that possibly clear up any
> confusion or does it just add confusion?  I personally believe the
> latter.  Is there a situation where \\ can be used to prevent `]' from
> having a special meaning?  In "[a\\]b]", the first `]' still has a
> special meaning, even though there might be some optical illusion
> making it look "quoted", the second `]' has no special meaning.

According to the Elisp manual "[a\\]b]" is poor practice.  You probably
mean "[a\\]b\\]" here.  Anyway, the first `]' has a special meaning but
it's not "inside" the character alternative.  It does have a special
meaning because `]' is special _outside_ character alternatives.

> I believe that a `]' should not be quoted at all if it is outside a
> character alternative, where it has no special meaning, unless I am
> overlooking something.  (Just tell what, in that case.)

That of terminating a character alternative.

>
> ELISP> (string-match "[a\\]b]" "]")
> nil
> ELISP> (string-match "[a\\]b]" "\\b")
> nil
> ELISP> (string-match "[a\\]b]" "\\b]")
> 0

According to the Elisp manual all these exhibit "poor practice" since
you didn't quote the second `]'s.  You should have complained about that
when you read the manual.






reply via email to

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