unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Abdulrahman Semrie <hsamireh@gmail.com>
Cc: 36251@debbugs.gnu.org
Subject: bug#36251: Regex library doesn't recognize ']' in a character class
Date: Tue, 18 Jun 2019 07:08:06 -0400	[thread overview]
Message-ID: <87r27rywum.fsf@netris.org> (raw)
In-Reply-To: <ad11135c-ebba-4ffb-827d-a8eebd7fa023@Canary> (Abdulrahman Semrie's message of "Sun, 16 Jun 2019 20:16:29 +0300")

Hi,

Abdulrahman Semrie <hsamireh@gmail.com> writes:

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

It turns out that there are several flavors of regular expressions in
common use, with different features and syntax.  The link you provided
is using PCRE (PHP) regular expressions (see the "flavor" pane on the
left), and there are three other supported flavors on that web site.

Guile's (ice-9 regex) module provides a simpler flavor of regexps known
as "POSIX extended regular expressions", implemented as a thin wrapper
around your system's POSIX regular expression library ('regcomp' and
'regexec').  The web site you referenced does not appear to support
POSIX extended regular expressions, but here are some links about them:

  https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions
  https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html#tag_09_04

One of the notable differences is that in POSIX extended regular
expressions, character classes do not support backslash escapes, but
instead use a more ad-hoc approach as <tomas@tuxteam.de> described.

     Regards,
       Mark





  parent reply	other threads:[~2019-06-18 11:08 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
2019-06-18 11:08 ` Mark H Weaver [this message]
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=87r27rywum.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=36251@debbugs.gnu.org \
    --cc=hsamireh@gmail.com \
    /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).