Re: Why this regexp matches?!

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: depesz(at)depesz(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Why this regexp matches?!
Date: 2012-02-04 08:54:34
Message-ID: CAFjNrYvOVm98tp=RcxnR95MCKKLQ=9ajXVw3F84exK=+ZLjZoA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4 February 2012 09:46, hubert depesz lubaczewski <depesz(at)depesz(dot)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(at)postgres:5840=# select regexp_replace( 'depesz depeszx depesz',
E'^(.*)( \\\\1)+$', E'\\\\1' );
regexp_replace
-----------------------
depesz depeszx depesz
(1 row)

regards
Szymon

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2012-02-04 08:58:39 Re: Why this regexp matches?!
Previous Message hubert depesz lubaczewski 2012-02-04 08:46:30 Why this regexp matches?!