Re: Why this regexp matches?! - Mailing list pgsql-general

From Szymon Guz
Subject Re: Why this regexp matches?!
Date
Msg-id CAFjNrYvOVm98tp=RcxnR95MCKKLQ=9ajXVw3F84exK=+ZLjZoA@mail.gmail.com
Whole thread Raw
In response to Why this regexp matches?!  (hubert depesz lubaczewski <depesz@depesz.com>)
Responses Re: Why this regexp matches?!
List pgsql-general


On 4 February 2012 09:46, hubert depesz lubaczewski <depesz@depesz.com> wrote:
select 'depesz depeszx depesz' ~ E'^(.*)( \\1)+$';

what's worse:
$ select regexp_replace( 'depesz depeszx depesz', E'^(.*)( \\1)+$', E'\\1' );
 regexp_replace
────────────────
 depesz
(1 row)

I know that Pg regexps are limited, but even grep's regexps match this
correctly:

=$ printf 'depesz depesz depesz\ndepesz depeszx depesz\n' | grep -E '^(.*)( \1)+$';
depesz depesz depesz

Best regards,

depesz


Hi,
some time ago I hit the same problem, however the solution was a little bit tricky. I didn't have time to investigate it, but this works:

postgres@postgres:5840=#  select regexp_replace( 'depesz depeszx depesz', E'^(.*)( \\\\1)+$', E'\\\\1' );
    regexp_replace     
-----------------------
 depesz depeszx depesz
(1 row)


regards
Szymon

pgsql-general by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Why this regexp matches?!
Next
From: hubert depesz lubaczewski
Date:
Subject: Re: Why this regexp matches?!