Re: BUG #15046: non-greedy ignored

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "bgailer(at)gmail(dot)com" <bgailer(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15046: non-greedy ignored
Date: 2018-02-03 01:48:56
Message-ID: 8100.1517622536@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Friday, February 2, 2018, PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Srikanth M K 2018-02-03 09:32:41 Re: Difference in behaviour between 9.6 and 10.1: GROUPING with ROLLUP , difference in order and error with unnest
Previous Message David G. Johnston 2018-02-03 01:16:05 Re: BUG #15046: non-greedy ignored