unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: 36251@debbugs.gnu.org
Subject: bug#36251: Regex library doesn't recognize ']' in a character class
Date: Sun, 16 Jun 2019 21:40:08 +0200	[thread overview]
Message-ID: <20190616194008.GA2901@tuxteam.de> (raw)
In-Reply-To: <ad11135c-ebba-4ffb-827d-a8eebd7fa023@Canary>

[-- Attachment #1: Type: text/plain, Size: 1690 bytes --]

On Sun, Jun 16, 2019 at 08:16:29PM +0300, Abdulrahman Semrie wrote:
> 
> I am using the pattern [\\[\\]a-zA-Z]+ to match a string with left or right bracket in it. However, the string-match function doesn’t match the ‘]’ character. To demonstrate with an example, try the following funciton:
> 
> (string-match "[\\[\\]a-zA-Z]+" "Text[ab]”)
> 
> The result for the above function should have been a match structure with Text[ab] matched. However, the string-match returns #f which is incorrect. To test if the pattern I am using was right, I tried on regex101.com and it works. Here (https://regex101.com/r/VAl6aI/1) is the link that demonstrates that it works.
> 
> Hence, the above leads me to believe there is a bug in the regex library that mishandles ] character in character-classes

If I understood you correctly, you are using POSIX regular
expressions. Within a bracket expression ([...]), you can't
escape ']' with a backslash. Just put the ] as first character,
like so:

  [][a-zA-Z]

Quoting the man page (regex(7)):

   A bracket expression is a list of characters enclosed in "[]".
   It normally matches any single character from the list (but see
   below).  If the list begins  with  '^', it  matches  any  single
   character  (but see below) not from the rest of the list. [...]

   To  include  a  literal ']' in the list, make it the first
   character (following a possible '^').  To include a literal
   '-', make it the first or last character, or the second endpoint
   of a range [...]

See also [1], but the man page is more complete.

(I'm assuming your Guile is linked against some POSIX regex library).

Cheers
-- t

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2019-06-16 19:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-16 17:16 bug#36251: Regex library doesn't recognize ']' in a character class Abdulrahman Semrie
2019-06-16 19:40 ` tomas [this message]
2019-06-18 11:08 ` Mark H Weaver
2019-06-18 11:20   ` tomas
2019-06-28 11:21   ` David Pirotte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190616194008.GA2901@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=36251@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).