regex subexpressions broken

2007-05-11 Thread odi
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: i686-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -march=athlon-tbird -O3 
-fomit-frame-pointer -pipe
uname output: Linux gollum 2.6.18-gentoo-r4 #1 PREEMPT Sat Dec 9 14:19:35 CET 
2006 i686 AMD Athlon(tm) processor AuthenticAMD GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 3.2
Patch Level: 15
Release Status: release

Description:
[[ "a b c" =~ "a (.) c" ]]
echo ${BASH_REMATCH[1]}

Does not return a result any more. It used to work.
Is that a Gentoo specific problem? Gentoo applies some patches I guess.

Regards

Ortwin



___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: regex subexpressions broken

2007-05-11 Thread Fran Litterio

Ortwin wrote:


[[ "a b c" =~ "a (.) c" ]]
echo ${BASH_REMATCH[1]}


Recently, a change was made to cause quotes to suppress the special meaning
of regular expression characters in the right-hand side of =~.  This is how
to do the above now:

   [[ "a b c" =~ a\ (.)\ c ]]

I submitted a patch to the Bash man page describing these new quoting
semantics.  Just in case it was missed, I've included it again (below).
--
Francis Litterio


--- bash.1.orig2006-10-03 08:54:26.0 -0400
+++ bash.12007-03-24 17:15:06.459699200 -0400
@@ -686,8 +686,19 @@
.if n .sp 1
An additional binary operator, \fB=~\fP, is available, with the same
precedence as \fB==\fP and \fB!=\fP.
-When it is used, the string to the right of the operator is considered
-an extended regular expression and matched accordingly (as in
\fIregex\fP(3)).
+When this operaor is used, the string to the right of the operator is
+considered an extended regular expression and matched accordingly (as
+in \fIregex\fP(3)).  If the regular expression string is quoted with
+either single or double quotes, the special meaning of the regular
+expression characters (such as '.', '*', '+', '[', ']', '(', ')',
+etc.) is suppressed.  Thus, if the regular expression string contains
+whitespace, it is best to escape the whitespace characters using '\\'
+instead of quoting the entire regular expression string, as follows:
+.if t .sp 0.5
+.if n .sp 1
+  \fB[[\fP "$DATA" \fB=~\fP foo\\ bar.*bletch \fB]]\fP
+.if t .sp 0.5
+.if n .sp 1
The return value is 0 if the string matches
the pattern, and 1 otherwise.
If the regular expression is syntactically incorrect, the conditional
___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash