unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How do I get a ] into a reg exp?
@ 2006-09-13 19:45 Lennart Borgman
  2006-09-13 20:16 ` David Hansen
  2006-09-13 20:21 ` David Kastrup
  0 siblings, 2 replies; 10+ messages in thread
From: Lennart Borgman @ 2006-09-13 19:45 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How do I get a ] into a reg exp?
  2006-09-13 19:45 How do I get a ] into a reg exp? Lennart Borgman
@ 2006-09-13 20:16 ` David Hansen
  2006-09-13 20:26   ` David Kastrup
  2006-09-13 20:21 ` David Kastrup
  1 sibling, 1 reply; 10+ messages in thread
From: David Hansen @ 2006-09-13 20:16 UTC (permalink / raw)


On Wed, 13 Sep 2006 21:45:58 +0200 Lennart Borgman wrote:

> How do I write
>
>    (re-search-forward "[a-z\]]")

"[][]" looks odd but works for me.  But IMHO that should be "[\\[\\]]".

David

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How do I get a ] into a reg exp?
  2006-09-13 19:45 How do I get a ] into a reg exp? Lennart Borgman
  2006-09-13 20:16 ` David Hansen
@ 2006-09-13 20:21 ` David Kastrup
  2006-09-13 21:31   ` Lennart Borgman
  1 sibling, 1 reply; 10+ messages in thread
From: David Kastrup @ 2006-09-13 20:21 UTC (permalink / raw)
  Cc: Emacs Devel

Lennart Borgman <lennart.borgman.073@student.lu.se> 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.)


-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How do I get a ] into a reg exp?
  2006-09-13 20:16 ` David Hansen
@ 2006-09-13 20:26   ` David Kastrup
  0 siblings, 0 replies; 10+ messages in thread
From: David Kastrup @ 2006-09-13 20:26 UTC (permalink / raw)


David Hansen <david.hansen@gmx.net> writes:

> On Wed, 13 Sep 2006 21:45:58 +0200 Lennart Borgman wrote:
>
>> How do I write
>>
>>    (re-search-forward "[a-z\]]")
>
> "[][]" looks odd but works for me.  But IMHO that should be "[\\[\\]]".

No.  \ is not special in character alternatives.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How do I get a ] into a reg exp?
  2006-09-13 20:21 ` David Kastrup
@ 2006-09-13 21:31   ` Lennart Borgman
  2006-09-13 21:35     ` Drew Adams
  2006-09-13 21:42     ` Lennart Borgman
  0 siblings, 2 replies; 10+ messages in thread
From: Lennart Borgman @ 2006-09-13 21:31 UTC (permalink / raw)
  Cc: Emacs Devel

David Kastrup wrote:
> Lennart Borgman <lennart.borgman.073@student.lu.se> 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: How do I get a ] into a reg exp?
  2006-09-13 21:31   ` Lennart Borgman
@ 2006-09-13 21:35     ` Drew Adams
  2006-09-13 21:42     ` Lennart Borgman
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2006-09-13 21:35 UTC (permalink / raw)


    >      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.

It's pretty standard, actually:
http://www.greenend.org.uk/rjk/2002/06/regexp.html.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How do I get a ] into a reg exp?
  2006-09-13 21:31   ` Lennart Borgman
  2006-09-13 21:35     ` Drew Adams
@ 2006-09-13 21:42     ` Lennart Borgman
  2006-09-13 21:48       ` Lennart Borgman
  1 sibling, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2006-09-13 21:42 UTC (permalink / raw)
  Cc: Emacs Devel

Lennart Borgman wrote:
> David Kastrup wrote:
>> Lennart Borgman <lennart.borgman.073@student.lu.se> 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How do I get a ] into a reg exp?
  2006-09-13 21:42     ` Lennart Borgman
@ 2006-09-13 21:48       ` Lennart Borgman
  2006-09-13 22:07         ` David Kastrup
  0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2006-09-13 21:48 UTC (permalink / raw)


Lennart Borgman wrote:
> Lennart Borgman wrote:
>> David Kastrup wrote:
>>> Lennart Borgman <lennart.borgman.073@student.lu.se> 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How do I get a ] into a reg exp?
  2006-09-13 21:48       ` Lennart Borgman
@ 2006-09-13 22:07         ` David Kastrup
  2006-09-13 22:10           ` Drew Adams
  0 siblings, 1 reply; 10+ messages in thread
From: David Kastrup @ 2006-09-13 22:07 UTC (permalink / raw)
  Cc: Emacs Devel

Lennart Borgman <lennart.borgman.073@student.lu.se> writes:

> Lennart Borgman wrote:
>>>>
>>>> (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.

Yes, [-+ is an empty range, since the first character is larger than
the last.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: How do I get a ] into a reg exp?
  2006-09-13 22:07         ` David Kastrup
@ 2006-09-13 22:10           ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2006-09-13 22:10 UTC (permalink / raw)


    Yes, [-+ is an empty range, since the first character is larger than
    the last.
    
Presumably, another example of "less is more" ;-).

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-09-13 22:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-13 19:45 How do I get a ] into a reg exp? Lennart Borgman
2006-09-13 20:16 ` David Hansen
2006-09-13 20:26   ` David Kastrup
2006-09-13 20:21 ` David Kastrup
2006-09-13 21:31   ` Lennart Borgman
2006-09-13 21:35     ` Drew Adams
2006-09-13 21:42     ` Lennart Borgman
2006-09-13 21:48       ` Lennart Borgman
2006-09-13 22:07         ` David Kastrup
2006-09-13 22:10           ` Drew Adams

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).