This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bug with grep 3.0.2 in cygwin 3.0.7


On 8/28/19 2:16 AM, akiki@free.fr wrote:
> Hi, 
> I encounter some problem with grep option -E on cygwin 3.0.7 
> 
> 
> echo "a^b" | grep "a^b" #answer a^b ie it's OK 

POSIX says:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html

"A BRE special character has special properties in certain contexts.
Outside those contexts, or when preceded by a <backslash>, such a
character is a BRE that matches the special character itself."
...
"A <circumflex> ( '^' ) shall be an anchor when used as the first
character of an entire BRE. The implementation may treat the
<circumflex> as an anchor when used as the first character of a
subexpression."

Since ^ is only special as the first character or in a [], and you have
used it for neither, this is a well-specified literal match.

> but 
> echo "a^b" | grep -E "a^b" #answer nothing " for me it's KO 

"An ERE special character has special properties in certain contexts.
Outside those contexts, or when preceded by a <backslash>, such a
character shall be an ERE that matches the special character itself."

"A <circumflex> ( '^' ) outside a bracket expression shall anchor the
expression or subexpression it begins to the beginning of a string; such
an expression or subexpression can match only a sequence starting at the
first character of a string. For example, the EREs "^ab" and "(^ab)"
match "ab" in the string "abcdef", but fail to match in the string
"cdefab", and the ERE "a^b" is valid, but can never match because the
'a' prevents the expression "^b" from matching starting at the first
character."

So in ERE, ^ is an anchor anywhere, while in BRE, ^ is an anchor only as
the first byte.  The difference you are observing matches POSIX.

> 
> 
> I have to backslash ^ to be OK like : grep -E 'a\^b' 

Correct.

> 
> 
> Is-it a bug ? 

No. (In fact, if you test on Linux, you'll see the same behavior, which
shows it is not specific to Cygwin).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]