GNU bug report logs - #12665
regexp fault for closing square bracket within character class

Previous Next

Package: guile;

Reported by: Panicz Maciej Godek <godek.maciek <at> gmail.com>

Date: Wed, 17 Oct 2012 19:59:01 UTC

Severity: normal

Done: Mark H Weaver <mhw <at> netris.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Mark H Weaver <mhw <at> netris.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#12665: closed (regexp fault for closing square bracket within
 character class)
Date: Thu, 18 Oct 2012 04:56:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 18 Oct 2012 00:54:01 -0400
with message-id <87txtsqt1y.fsf <at> tines.lan>
and subject line Re: bug#12665: regexp fault for closing square bracket within character class
has caused the debbugs.gnu.org bug report #12665,
regarding regexp fault for closing square bracket within character class
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
12665: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12665
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Panicz Maciej Godek <godek.maciek <at> gmail.com>
To: bug-guile <at> gnu.org
Subject: regexp fault for closing square bracket within character class
Date: Wed, 17 Oct 2012 21:33:58 +0200
guile 2.0.5-deb+1-1
(string-match "[\\[]" "[")
===> #("[" (0 . 1))
(string-match "[\\]]" "]")
===> #f


[Message part 3 (message/rfc822, inline)]
From: Mark H Weaver <mhw <at> netris.org>
To: Panicz Maciej Godek <godek.maciek <at> gmail.com>
Cc: 12665-done <at> debbugs.gnu.org
Subject: Re: bug#12665: regexp fault for closing square bracket within
	character class
Date: Thu, 18 Oct 2012 00:54:01 -0400
Panicz Maciej Godek <godek.maciek <at> gmail.com> writes:
> guile 2.0.5-deb+1-1
> (string-match "[\\[]" "[")
> ===> #("[" (0 . 1))
> (string-match "[\\]]" "]")
> ===> #f

As documented in "Syntax of Regular Expressions" of the Emacs manual
(to which section 6.15 of the Guile manual refers):

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

For example:

  (string-match "[]\\]" "]")   ==>  #("]" (0 . 1))

Note that backslash is also a member of this character class, and of the
character class in your first example:

  (string-match "[]\\]" "\\")  ==>  #("\\" (0 . 1))
  (string-match "[\\[]" "\\")  ==>  #("\\" (0 . 1))

You might have been thinking that the backslash would escape the square
brackets in your class, but that's not how it works within character
classes.  '[' can be included anywhere in a character class without
being escaped, and ']' and '-' are handled as described above.

    Regards,
      Mark


This bug report was last modified 12 years and 270 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.