[pcre-dev] [Bug 2294] pcregrep -E

Top Page

Reply to this message
Author: admin
To: pcre-dev
Subject: [pcre-dev] [Bug 2294] pcregrep -E

--- Comment #1 from Philip Hazel <ph10@???> ---
(In reply to Elliott Hughes from comment #0)

> In Android P and earlier, grep had the options -e and -E.
> -e supported basic regular expressions (BRE's)
> -E supported extended regular expressions (ERE's, which includes or, and,
> etc)
> The PCRE grep package only has -e.
> In PCRE, -e is the equivalent to Android P's -E. The -e flag has no
> equivalent in PCRE.

Not quite sure I follow you here: in pcre2grep -e is just a way of specifying a
pattern to be matched. The pattern is always a Perl pattern.

However, have you taken a look at the more recent releases of PCRE2? From 10.30
there is support for an experimental function called pcre2_pattern_convert()
which is supposed to convert POSIX BREs and EREs into Perl patterns. See the
pcre2convert man page. If this will do what you want, it should be relatively
straightforward to introduce it as an option into pcre2grep. I don't know how
much use this feature has had, so there is a higher chance of bugs than in the
rest of PCRE (I imagine).

> from https://www.pcre.org/current/doc/html/pcre2convert.html it looks like i
> can implement the BRE/ERE behavior -- and i'm actually volunteering to send
> you the patch -- but i wanted to ask whether you'd accept such a change, and
> whether you'd want it behind an #if __ANDROID__ or similar?

Ah, I see you've already found pcre2convert.

> basically i'd like to make the default BRE and add -E for ERE, to match
> POSIX (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html).

That can't happen - the default must remain Perl regex as it always has been.
So some other option is needed for BRE (possibly -G like GNU grep). I suppose,
however, we could invent a compile-time option that sets what the default is,
and add -P for completeness. Then it would be the default default that is -P.
But I don't feel too comfortable doing that, because it would mean that
"pcre2grep" would be different on different implementations. Perhaps a better
plan is to implement -G, and then in Android you could make "grep" be an alias
for "pcre2grep -G". We probably don't need #if __ANDROID__.

> i'm not sure whether you consider the current PCRE grep behavior a bug or a
> feature.

Definitely a feature! It always was meant to be a Perl-style grep. That was the
whole point of writing it, because at the time no other grep had Perl pattern
support. (And I wanted to write a "real" PCRE application to make use of the
PCRE library, when it was very new - 20 years ago.)

I am always open to suggestions and/or patches for PCRE2 and pcre2grep. I'll
also take a look at the code myself - but not for a few days there because are
other things to do first (not only in PCRE :-)

You are receiving this mail because:
You are on the CC list for the bug.