Postgres regexp matching failure?

Поиск
Список
Период
Сортировка
От Mario Splivalo
Тема Postgres regexp matching failure?
Дата
Msg-id 1157451491.27799.6.camel@localhost.localdomain
обсуждение исходный текст
Ответы Re: Postgres regexp matching failure?
Re: Postgres regexp matching failure?
Список pgsql-sql
I have an regular expression, wich works fine in Java or python, but I
don't seem to be able to make it work in postgres. Regular expression
needs to match everything begining with '+' (plus sign) or letters
'STOP', 'stop', 'StoP', or any other combination pronounced 'stop'.

Here is the python example:

>>> import re
>>> p = re.compile(r'^\s*(?:[\+|-]|(?:[sS][tT][oO][pP]\b)).*$')
>>> p.match('+mario').group(0)
'+mario'
>>> p.match('+mario works').group(0)
'+mario works'
>>> p.match('mario works').group(0)
Traceback (most recent call last): File "<stdin>", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'group'
>>> p.match('stop works').group(0)
'stop works'
>>>

Now, here is what happens if I try this in postgres:

pulitzer2=# select '+mario' ~ '^\s*(?:[\+|-]|(?:[sS][tT][oO][pP]\b)).*
$';?column?
----------t
(1 row)

This one is ok.



pulitzer2=# select '+mario works' ~ '^\s*(?:[\
+|-]|(?:[sS][tT][oO][pP]\b)).*$';?column?
----------t
(1 row)



This one is also ok.

pulitzer2=# select 'mario works' ~ '^\s*(?:[\
+|-]|(?:[sS][tT][oO][pP]\b)).*$';?column?
----------f
(1 row)

Same as this one, also ok.


pulitzer2=# select 'stop works' ~ '^\s*(?:[\
+|-]|(?:[sS][tT][oO][pP]\b)).*$';?column?
----------f
(1 row)

Here, postgres should return true, but it gives me false. 

I'd appreciate any hints on what is wrong here.

Thank you in advance,
Mario
-- 
Mario Splivalo
Mob-Art
mario.splivalo@mobart.hr

"I can do it quick, I can do it cheap, I can do it well. Pick any two."




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

Предыдущее
От: "M. Santosa"
Дата:
Сообщение: pg_dump
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: pg_dump