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

From Bruno Wolff III
Subject Re: Negative lookbehind assertions in regexs
Date
Msg-id 20050829162103.GA32443@wolff.to
Whole thread Raw
In response to Negative lookbehind assertions in regexs  ("Julian Scarfe" <julian@avbrief.com>)
List pgsql-sql
On Mon, Aug 29, 2005 at 14:11:37 +0100, Julian Scarfe <julian@avbrief.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)


pgsql-sql by date:

Previous
From: "Julian Scarfe"
Date:
Subject: Negative lookbehind assertions in regexs
Next
From: andy rost
Date:
Subject: sqlstate 02000 while declaring cursor/freeing prepared statements