From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: bgailer@gmail.com <bgailer@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #15046: non-greedy ignored
Date: Fri, 02 Feb 2018 20:48:56 -0500
Message-ID: <8100.1517622536@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwY-QAB7Gi+2q_m3SMFM4SQnXbDuk=vAERg0KL04LeiSiA@mail.gmail.com>
References: <151761974148.1240.12558693542380794378@wrigleys.postgresql.org>
<CAKFQuwY-QAB7Gi+2q_m3SMFM4SQnXbDuk=vAERg0KL04LeiSiA@mail.gmail.com>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, bgailer@gmail.com
Subject: Re: BUG #15046: non-greedy ignored
In-Reply-To: <8100.1517622536@sss.pgh.pa.us>
References: <151761974148.1240.12558693542380794378@wrigleys.postgresql.org> <CAKFQuwY-QAB7Gi+2q_m3SMFM4SQnXbDuk=vAERg0KL04LeiSiA@mail.gmail.com> <8100.1517622536@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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