Re: Why this regexp matches?!

From: Alban Hertroys <haramrae(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 18:31:25
Message-ID: 5F2D84C1-179A-42BA-A5F9-F338B93E8AD7@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 4 Feb 2012, at 9:46, hubert depesz lubaczewski wrote:

> select 'depesz depeszx depesz' ~ E'^(.*)( \\1)+$';

Peculiar.

It's probably no use to you, but a version where the repetition is expanded (for that particular string) works:

select 'depesz depeszx depesz' ~ E'^(.*)( \\1)( \\1)$';

And this works too:

select 'depesz depeszx depesz' ~ E'^(depesz)( \\1)+$';

Apparently something odd is going on between the wildcard, the repetitive part and the back-reference. That could be just us not seeing what's wrong with the expression or be an actual bug.

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

Limited? They're really not. According to the docs they are beyond POSIX compliant, even including several extensions as they appear in, among others, Perl. That said, the docs do mention a known limitation with braces and forward-references - maybe this is related.

Alban Hertroys

--
The scale of a problem often equals the size of an ego.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2012-02-04 19:58:38 Re: Why this regexp matches?!
Previous Message Tom Lane 2012-02-04 17:58:21 Re: debugging the server[ module causes server cash]