pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dawid Kuroczko <qnex42@gmail.com>
To: Julian Scarfe <julian@avbrief.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Negative lookbehind assertions in regexs
Date: Sat, 3 Sep 2005 19:18:51 +0200
Message-ID: <758d5e7f050903101842197d38@mail.gmail.com> (raw)
In-Reply-To: <09d701c5b098$10afee50$0600a8c0@Wilbur>
References: <001a01c5ac84$496fc750$1102a8c0@dream>
	<008901c5ac9b$31bb8b50$0600a8c0@Wilbur>
	<20050829162103.GA32443@wolff.to>
	<09d701c5b098$10afee50$0600a8c0@Wilbur>

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

view thread (5+ messages)

Message-ID: <758d5e7f050903101842197d38@mail.gmail.com>
Permalink:  ../758d5e7f050903101842197d38@mail.gmail.com/
Also on:    postgresql.org/message-id/758d5e7f050903101842197d38@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: qnex42@gmail.com, julian@avbrief.com
  Subject: Re: Negative lookbehind assertions in regexs
  In-Reply-To: <758d5e7f050903101842197d38@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox