public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: cygwin@cygwin.com, akiki@free.fr
Subject: Re: bug with grep 3.0.2 in cygwin 3.0.7
Date: Wed, 28 Aug 2019 13:33:00 -0000	[thread overview]
Message-ID: <a78fa9ac-a336-493a-c9f7-67fc8efe42b5@redhat.com> (raw)
In-Reply-To: <1207614124.1217647925.1566976580120.JavaMail.root@zimbra76-e14.priv.proxad.net>


[-- Attachment #1.1: Type: text/plain, Size: 2111 bytes --]

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 #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2019-08-28 13:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1910922536.1217465852.1566975322390.JavaMail.root@zimbra76-e14.priv.proxad.net>
2019-08-28  8:32 ` akiki
2019-08-28 12:51   ` Eliot Moss
2019-08-28 13:33   ` Eric Blake [this message]
2019-08-29 19:20   ` Andrey Repin
2019-08-30  6:12     ` Eliot Moss
2019-08-30  7:48       ` Brian Inglis
2019-08-30 15:34         ` Eliot Moss
2019-08-30  7:50       ` Duncan Roe
2019-08-30 13:04         ` Jose Isaias Cabrera
2019-08-30  7:55       ` Andrey Repin
2019-09-23 14:42   ` Chris Wagner

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a78fa9ac-a336-493a-c9f7-67fc8efe42b5@redhat.com \
    --to=eblake@redhat.com \
    --cc=akiki@free.fr \
    --cc=cygwin@cygwin.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).