Re: Negative lookbehind assertions in regexs - Mailing list pgsql-sql

From Dawid Kuroczko
Subject Re: Negative lookbehind assertions in regexs
Date
Msg-id 758d5e7f050903101842197d38@mail.gmail.com
Whole thread Raw
In response to Re: Negative lookbehind assertions in regexs  ("Julian Scarfe" <julian@avbrief.com>)
List pgsql-sql
On 9/3/05, Julian Scarfe <julian@avbrief.com> wrote:
>> I'd like a regex that matches 'CD' but not 'ABCD' in any part of the
>> regex.

From: "Bruno Wolff III" <bruno@wolff.to>

> Something like:
> (^.?CD)|([^B]CD)|([^A]BCD)

Thanks to Bruno, and to Dawid who replied offline.  The above does the job
nicely.

I intended to post Cc: to the list, but somehow I didn't (blame it on computers,
I just assumed Cc is set ;)).

Anyway, when perl_re's are craved for, once could use PLperl for this:

CREATE OR REPLACE FUNCTION perl_re(v text, r text)
   RETURNS boolean LANGUAGE plperl STRICT IMMUTABLE AS $$
       my ($val, $re) = @_;
       return ($val =~ m{$re}) ? 't' : 'f';
   $$;


...though it should be noted that queries WHERE perl_re(col, '(?<!AB)CD')
will not use indexes. (unless there are functional indexes on that function,
but then you would need one index for each regex used).

   Regards,
        Dawid

pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Negative lookbehind assertions in regexs
Next
From: Neil Dugan
Date:
Subject: joining two simular (but not identical tables)