Re: Negative lookbehind assertions in regexs

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Julian Scarfe <julian(at)avbrief(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Negative lookbehind assertions in regexs
Date: 2005-08-29 16:21:03
Message-ID: 20050829162103.GA32443@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, Aug 29, 2005 at 14:11:37 +0100,
Julian Scarfe <julian(at)avbrief(dot)com> wrote:
> I'd like a regex that matches 'CD' but not 'ABCD' in any part of the regex.
>
> Is there a workaround that allows me to do this as a single regex?
>
> I know I could and together a ~ and !~ like this
>
> # select ('CD' ~ 'CD') and ('CD' !~ 'ABCD');
> ?column?
> ----------
> t
> (1 row)
>
> # select ('ABCD' ~ 'CD') and ('ABCD' !~ 'ABCD');
> ?column?
> ----------
> f
> (1 row)

The above code won't work because there could be both CD and ABCD in the
string. What you want to do is match all of the valid possibilities.
Something like:
(^.?CD)|([^B]CD)|([^A]BCD)

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message andy rost 2005-08-29 19:28:24 sqlstate 02000 while declaring cursor/freeing prepared statements
Previous Message Julian Scarfe 2005-08-29 13:11:37 Negative lookbehind assertions in regexs