Re: BUG #15046: non-greedy ignored - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #15046: non-greedy ignored
Date
Msg-id 8100.1517622536@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #15046: non-greedy ignored  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: BUG #15046: non-greedy ignored  (Bob Gailer <bgailer@gmail.com>)
List pgsql-bugs
"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


pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #15046: non-greedy ignored
Next
From: Srikanth M K
Date:
Subject: Re: Difference in behaviour between 9.6 and 10.1: GROUPING withROLLUP , difference in order and error with unnest