X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 69C3B9FB341 for ; Tue, 5 Sep 2006 07:18:22 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 99719-08 for ; Tue, 5 Sep 2006 07:18:16 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by postgresql.org (Postfix) with ESMTP id 1BB109FB340 for ; Tue, 5 Sep 2006 07:18:16 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id 3084517A83 for ; Tue, 5 Sep 2006 12:18:14 +0200 (CEST) Received: from pjetlic.mobart.hr ([127.0.0.1]) by localhost (pjetlic [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 02484-07-3 for ; Tue, 5 Sep 2006 12:18:12 +0200 (CEST) Received: from mike.mobart.hr (mike.mobart.hr [192.168.10.94]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by pjetlic.mobart.hr (Postfix) with ESMTP id 4C15C17A67 for ; Tue, 5 Sep 2006 12:18:12 +0200 (CEST) Subject: Postgres regexp matching failure? From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-sql@postgresql.org Content-Type: text/plain Organization: Mob-Art Date: Tue, 05 Sep 2006 12:18:11 +0200 Message-Id: <1157451491.27799.6.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by OpenSource AV+AS Mail Server X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.276 tagged_above=0 required=5 tests=AWL, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/18 X-Sequence-Number: 26229 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 "", 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."