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