From: Tom Lane <tgl@sss.pgh.pa.us>
To: Markhof, Ingolf <ingolf.markhof@de.verizon.com>
Cc: pgsql-general@postgresql.org
Subject: Re: [E] Re: Regexp_replace bug / does not terminate on long strings
Date: Fri, 20 Aug 2021 12:52:44 -0400
Message-ID: <1917678.1629478364@sss.pgh.pa.us> (raw)
In-Reply-To: <CALZg0g4T5u+9DUomsuN913MK_TS1GZM=8pMuJR+j=-0yiQdJrQ@mail.gmail.com>
References: <CALZg0g4FA1Xc5UMLrGBKM--erUGEAhe8GGLE-YcN7=O6rw2=0A@mail.gmail.com>
<1809528.1629412955@sss.pgh.pa.us>
<CALZg0g4T5u+9DUomsuN913MK_TS1GZM=8pMuJR+j=-0yiQdJrQ@mail.gmail.com>
"Markhof, Ingolf" <ingolf.markhof@de.verizon.com> writes:
> thank you very much for your reply. Actually, I was assuming all these
> regular expressions are based on the same core implementation.
They are not. There are at least three fundamentally different
implementation technologies (DFA, NFA, hybrid). Friedl's "Mastering
Regular Expressions" cites multiple different programs using each
of those, every one of which behaves a bit differently when you start
poking at corner cases. And that's just in the open-source world;
I don't know what Oracle is using, but I bet it ain't open source.
> I am also surprised that you say the (\1)+ subpattern is computationally
> expensive. Regular expressions are greedy by default. I.e. in case of a*
> matching against a string of 1000 a's, the system will not try a, aa, aaa,
> ... and so on, right? Instead, it will consume all the a's in one go.
"a*" is easy. "(a*)\1" is less easy --- if you let the a* consume the
whole string, you will not get a match, even though one is possible.
In general, backrefs create a mess in what would otherwise be a pretty
straightforward concept :-(.
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-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, ingolf.markhof@de.verizon.com
Subject: Re: [E] Re: Regexp_replace bug / does not terminate on long strings
In-Reply-To: <1917678.1629478364@sss.pgh.pa.us>
References: <CALZg0g4FA1Xc5UMLrGBKM--erUGEAhe8GGLE-YcN7=O6rw2=0A@mail.gmail.com> <1809528.1629412955@sss.pgh.pa.us> <CALZg0g4T5u+9DUomsuN913MK_TS1GZM=8pMuJR+j=-0yiQdJrQ@mail.gmail.com> <1917678.1629478364@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