pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15046: non-greedy ignored
4+ messages / 4 participants
[nested] [flat]

* BUG #15046: non-greedy ignored
@ 2018-02-03 01:02 PG Bug reporting form <noreply@postgresql.org>
  2018-02-03 01:16 ` Re: BUG #15046: non-greedy ignored David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: PG Bug reporting form @ 2018-02-03 01:02 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: bgailer@gmail.com

The following bug has been logged on the website:

Bug reference:      15046
Logged by:          Bob Gailer
Email address:      bgailer@gmail.com
PostgreSQL version: 10.1
Operating system:   windows 10
Description:        

I start psql; enter:

postgres=# select regexp_replace('a(d)s(e)f', '\(.*?\)', '', 'g');
 regexp_replace
----------------
 asf
(1 row)

Works as expected. Then I add |q to the pattern, and the .*? becomes
greedy!

postgres=# select regexp_replace('a(d)s(e)f', '\(.*?\)|q', '', 'g');
 regexp_replace
----------------
 af
(1 row)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #15046: non-greedy ignored
  2018-02-03 01:02 BUG #15046: non-greedy ignored PG Bug reporting form <noreply@postgresql.org>
@ 2018-02-03 01:16 ` David G. Johnston <david.g.johnston@gmail.com>
  2018-02-03 01:48   ` Re: BUG #15046: non-greedy ignored Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: David G. Johnston @ 2018-02-03 01:16 UTC (permalink / raw)
  To: bgailer@gmail.com <bgailer@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

On Friday, February 2, 2018, PG Bug reporting form <noreply@postgresql.org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference:      15046
> Logged by:          Bob Gailer
> Email address:      bgailer@gmail.com
> PostgreSQL version: 10.1
> Operating system:   windows 10
> Description:
>
> I start psql; enter:
>
> postgres=# select regexp_replace('a(d)s(e)f', '\(.*?\)', '', 'g');
>  regexp_replace
> ----------------
>  asf
> (1 row)
>
> Works as expected. Then I add |q to the pattern, and the .*? becomes
> greedy!
>
> postgres=# select regexp_replace('a(d)s(e)f', '\(.*?\)|q', '', 'g');
>  regexp_replace
> ----------------
>  af
> (1 row)
>
>
This seems to be explained by the final greediness rule:

https://www.postgresql.org/docs/10/static/functions-matching.html#POSIX-MATCHING-RULES


   -

   An RE consisting of two or more branches connected by the | operator is
   always greedy.


   David J.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #15046: non-greedy ignored
  2018-02-03 01:02 BUG #15046: non-greedy ignored PG Bug reporting form <noreply@postgresql.org>
  2018-02-03 01:16 ` Re: BUG #15046: non-greedy ignored David G. Johnston <david.g.johnston@gmail.com>
@ 2018-02-03 01:48   ` Tom Lane <tgl@sss.pgh.pa.us>
  2018-02-03 19:08     ` Re: BUG #15046: non-greedy ignored Bob Gailer <bgailer@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2018-02-03 01:48 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: bgailer@gmail.com <bgailer@gmail.com>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Friday, February 2, 2018, PG Bug reporting form <noreply@postgresql.org>
> wrote:
>> Works as expected. Then I add |q to the pattern, and the .*? becomes
>> greedy!

> This seems to be explained by the final greediness rule:
> https://www.postgresql.org/docs/10/static/functions-matching.html#POSIX-MATCHING-RULES
>    An RE consisting of two or more branches connected by the | operator is
>    always greedy.

Yeah.  That subsection also contains some useful advice about how to
control greediness decisions --- in this case, wrapping the whole
thing with (...){1,1}? might do what you want.

The short answer, perhaps, is that non-greedy patterns are not
standardized by POSIX and you shouldn't expect that all regex
engines do them the same way.  Ours is definitely different
from Perl's, for example.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #15046: non-greedy ignored
  2018-02-03 01:02 BUG #15046: non-greedy ignored PG Bug reporting form <noreply@postgresql.org>
  2018-02-03 01:16 ` Re: BUG #15046: non-greedy ignored David G. Johnston <david.g.johnston@gmail.com>
  2018-02-03 01:48   ` Re: BUG #15046: non-greedy ignored Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-02-03 19:08     ` Bob Gailer <bgailer@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Bob Gailer @ 2018-02-03 19:08 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>; David G. Johnston <david.g.johnston@gmail.com>

Thanks! Rtfp, eh?

On Feb 2, 2018 8:48 PM, "Tom Lane" <tgl@sss.pgh.pa.us> wrote:

> "David G. Johnston" <david.g.johnston@gmail.com> writes:
> > On Friday, February 2, 2018, PG Bug reporting form <
> noreply@postgresql.org>
> > wrote:
> >> Works as expected. Then I add |q to the pattern, and the .*? becomes
> >> greedy!
>
> > This seems to be explained by the final greediness rule:
> > https://www.postgresql.org/docs/10/static/functions-
> matching.html#POSIX-MATCHING-RULES
> >    An RE consisting of two or more branches connected by the | operator
> is
> >    always greedy.
>
> Yeah.  That subsection also contains some useful advice about how to
> control greediness decisions --- in this case, wrapping the whole
> thing with (...){1,1}? might do what you want.
>
> The short answer, perhaps, is that non-greedy patterns are not
> standardized by POSIX and you shouldn't expect that all regex
> engines do them the same way.  Ours is definitely different
> from Perl's, for example.
>
>                         regards, tom lane
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-02-03 19:08 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-02-03 01:02 BUG #15046: non-greedy ignored PG Bug reporting form <noreply@postgresql.org>
2018-02-03 01:16 ` David G. Johnston <david.g.johnston@gmail.com>
2018-02-03 01:48   ` Tom Lane <tgl@sss.pgh.pa.us>
2018-02-03 19:08     ` Bob Gailer <bgailer@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox