Negative lookbehind assertions in regexs

Поиск
Список
Период
Сортировка
От Julian Scarfe
Тема Negative lookbehind assertions in regexs
Дата
Msg-id 008901c5ac9b$31bb8b50$0600a8c0@Wilbur
обсуждение исходный текст
Ответ на PostgreSQL help  ("Shavonne Marietta Wijesinghe" <shavonne.marietta@studioform.it>)
Ответы Re: Negative lookbehind assertions in regexs  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-sql
I'd like a regex that matches 'CD' but not 'ABCD' in any part of the regex.

In Perl I'd use a negative lookbehind assertion (?<!AB)CD to do the job:

$ cat lb.pl
print "CD: ",   'CD'   =~ /(?<!AB)CD/, "\n";
print "XYCD: ", 'XYCD' =~ /(?<!AB)CD/, "\n";
print "ABCD: ", 'ABCD' =~ /(?<!AB)CD/, "\n";

$ perl lb.pl
CD: 1
XYCD: 1
ABCD:

But Postgresql (7.4) doesn't seem to like that:

# select 'ABCD' ~ '(?<!AB)CD';
ERROR:  invalid regular expression: quantifier operand invalid

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)

but changing the SQL would break the existing paradigm.

TIA

Julian 




В списке pgsql-sql по дате отправления:

Предыдущее
От: PFC
Дата:
Сообщение: Re: PostgreSQL help
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Negative lookbehind assertions in regexs