From: Bruno Wolff III <bruno@wolff.to>
To: Julian Scarfe <julian@avbrief.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Negative lookbehind assertions in regexs
Date: Mon, 29 Aug 2005 11:21:03 -0500
Message-ID: <20050829162103.GA32443@wolff.to> (raw)
In-Reply-To: <008901c5ac9b$31bb8b50$0600a8c0@Wilbur>
References: <001a01c5ac84$496fc750$1102a8c0@dream>
<008901c5ac9b$31bb8b50$0600a8c0@Wilbur>
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)
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: bruno@wolff.to, julian@avbrief.com
Subject: Re: Negative lookbehind assertions in regexs
In-Reply-To: <20050829162103.GA32443@wolff.to>
* 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