[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep backreference seems to invalidate --ignore-case
From: |
Julian Foad |
Subject: |
Re: grep backreference seems to invalidate --ignore-case |
Date: |
Mon, 19 Dec 2005 21:28:21 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050511 |
Mabry Tyson wrote:
I found what I believe to be a failure of grep to match something it
should. It appears that the use of a backreference invalidates the
existence of an --ignore-case switch.
Thanks for this well-written bug report.
ftp://ftp.gnu.org/gnu/grep/grep-2.5.1a.tar.gz
manresa 183: cat /tmp/test
A abcd abcd
manresa 184: src/grep --ignore-case 'a \(abcd\) \1' /tmp/test
(no output)
In the development (CVS) version of GNU grep, lots of problems related to
case-insensitive matching have been fixed, and this now works (matches the line).
Hopefully a new version will be released one day.
manresa 51: cat /tmp/test2
a abcd aBcD
manresa 52: src/grep --ignore-case 'a \(abcd\) \1' /tmp/test2
(no output)
This case is also fixed: the back-reference matches case-insensitively.
In this case, however, the documentation is somewhat ambiguous.
--ignore-case is documented as "Ignore case distinctions in both the
PATTERN and the input files." A backreference is documented as "matches
the substring previously matched by the Nth parenthesized subexpression
of the regular expression." It isn't clear whether a backreference
must match the substring exactly, or possibly match it, ignoring
case. It appears that at least the grep used in Solaris matched the
substring, ignoring case if --ignore-case is also given. I would argue
that this is the correct behavior as the --ignore-case indicates to
ignore the case in the input files. However this is resolved, the
documentation should clarify what it does.
I agree with you, and that is what GNU grep (CVS head) currently does.
I suppose it would be good to include a few words to this effect in the
documentation; I'll make a note to do so. Suggestions welcome.
Thanks again for the report.
- Julian