From: hubert depesz lubaczewski <depesz@depesz.com>
To: kosiodg@yahoo.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17761: Questionable regular expression behavior
Date: Fri, 27 Jan 2023 13:42:34 +0100
Message-ID: <Y9PGupnpVoN/uQ2w@depesz.com> (raw)
In-Reply-To: <17761-5a78c34533f3ab72@postgresql.org>
References: <17761-5a78c34533f3ab72@postgresql.org>
On Fri, Jan 27, 2023 at 09:27:35AM +0000, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference: 17761
> Logged by: Konstantin Geordzhev
> Email address: kosiodg@yahoo.com
> PostgreSQL version: 11.10
> Operating system: tested online
> Description:
>
> Executing:
> select regexp_matches('a 1x1250x2500',
> '(a).*?([1-9]\d*)\s*x\s*([1-9]\d*)(?:\s*x\s*([1-9]\d*))?');
> returns: {a,1,1,NULL}
> while executing:
> select regexp_matches('a 1x1250x2500',
> '(a|b).*?([1-9]\d*)\s*x\s*([1-9]\d*)(?:\s*x\s*([1-9]\d*))?');
> returns: {a,1,1250,2500}
>
> Shouldn't both results be equal?
The problem is, afair, that there is some state in pg's regexp engine
that makes greedy/ungreedy decision once per regexp.
I don't recall details, but my take from back when I learned about it
(years ago) is to try to avoid things like .*?
Instead you can:
#v+
$ select regexp_matches('a 1x1250x2500', '(a)\D*([1-9]\d*)\s*x\s*([1-9]\d*)(?:\s*x\s*([1-9]\d*))?');
regexp_matches
─────────────────
{a,1,1250,2500}
(1 row)
#v-
depesz
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: depesz@depesz.com, kosiodg@yahoo.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17761: Questionable regular expression behavior
In-Reply-To: <Y9PGupnpVoN/uQ2w@depesz.com>
* 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