Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ehmwx-00086V-Gh for pgsql-bugs@arkaria.postgresql.org; Sat, 03 Feb 2018 01:49:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehmwv-00030e-HP for pgsql-bugs@arkaria.postgresql.org; Sat, 03 Feb 2018 01:49:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ehmwv-00030V-8Y for pgsql-bugs@lists.postgresql.org; Sat, 03 Feb 2018 01:49:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ehmws-0005Gc-Iw for pgsql-bugs@lists.postgresql.org; Sat, 03 Feb 2018 01:49:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w131muTD008101; Fri, 2 Feb 2018 20:48:56 -0500 From: Tom Lane To: "David G. Johnston" cc: "bgailer@gmail.com" , "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #15046: non-greedy ignored In-reply-to: References: <151761974148.1240.12558693542380794378@wrigleys.postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Fri, 02 Feb 2018 18:16:05 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <8099.1517622536.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 02 Feb 2018 20:48:56 -0500 Message-ID: <8100.1517622536@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Friday, February 2, 2018, PG Bug reporting form > 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