Re: BUG #15046: non-greedy ignored

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "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:16:05
Message-ID: CAKFQuwY-QAB7Gi+2q_m3SMFM4SQnXbDuk=vAERg0KL04LeiSiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Friday, February 2, 2018, PG Bug reporting form <noreply(at)postgresql(dot)org>
wrote:

> The following bug has been logged on the website:
>
> Bug reference: 15046
> Logged by: Bob Gailer
> Email address: bgailer(at)gmail(dot)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.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2018-02-03 01:48:56 Re: BUG #15046: non-greedy ignored
Previous Message PG Bug reporting form 2018-02-03 01:02:21 BUG #15046: non-greedy ignored