Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mH7lD-0006aV-KP for pgsql-general@arkaria.postgresql.org; Fri, 20 Aug 2021 16:52:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mH7lC-0001BO-FU for pgsql-general@arkaria.postgresql.org; Fri, 20 Aug 2021 16:52:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mH7lC-0001BG-6U for pgsql-general@lists.postgresql.org; Fri, 20 Aug 2021 16:52:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mH7l9-00088v-ST for pgsql-general@postgresql.org; Fri, 20 Aug 2021 16:52:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 17KGqiiK1917679; Fri, 20 Aug 2021 12:52:44 -0400 From: Tom Lane To: "Markhof, Ingolf" cc: pgsql-general@postgresql.org Subject: Re: [E] Re: Regexp_replace bug / does not terminate on long strings In-reply-to: References: <1809528.1629412955@sss.pgh.pa.us> Comments: In-reply-to "Markhof, Ingolf" message dated "Fri, 20 Aug 2021 18:11:41 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1917677.1629478364.1@sss.pgh.pa.us> Date: Fri, 20 Aug 2021 12:52:44 -0400 Message-ID: <1917678.1629478364@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Markhof, Ingolf" 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