[Top][All Lists]

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

bug#36251: Regex library doesn't recognize ']' in a character class

From: Mark H Weaver
Subject: bug#36251: Regex library doesn't recognize ']' in a character class
Date: Tue, 18 Jun 2019 07:08:06 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)


Abdulrahman Semrie <address@hidden> 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:


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 <address@hidden> described.


reply via email to

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