emacs-devel
[Top][All Lists]
Advanced

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

Re: How do I get a ] into a reg exp?


From: Lennart Borgman
Subject: Re: How do I get a ] into a reg exp?
Date: Wed, 13 Sep 2006 23:48:02 +0200
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)

Lennart Borgman wrote:
Lennart Borgman wrote:
David Kastrup wrote:
Lennart Borgman <address@hidden> writes:

How do I write

   (re-search-forward "[a-z\]]")

I mean how do I get the ] into the characters to search for? It works
if I remove a-z. Looks like a bug to me.

\] is the same as ] in string syntax.  Anyway:

(info "(emacs) Regexps")

     To include a `]' in a character set, you must make it the first
     character.  For example, `[]a]' matches `]' or `a'.  To include a
     `-', write `-' as the first or last character of the set, or put
     it after a range.  Thus, `[]-]' matches both `]' and `-'.

     To include `^' in a set, put it anywhere but at the beginning of
     the set.  (At the beginning, it complements the set--see below.)

Thanks. That was a surprise.

New surprise. I still can not get it to work. This is my actual search:

  (re-search-forward "'\\([][-+a-zA-Z~<>!;,:.'\"%/?(){}$^0|]\\)'" nil t)


The above version does not match [  -- in the parenthesis.
But this one works:

    (re-search-forward "'\\([][+a-zA-Z~<>!;,:.'\"%/?(){}$^0|-]\\)'" nil t)

The - must be last. Thanks again.




reply via email to

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