On Mon, Aug 29, 2005 at 14:11:37 +0100, Julian Scarfe <[EMAIL PROTECTED]> 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) ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings