X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7D8859DC9D5 for ; Wed, 4 Jan 2006 10:50:32 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30198-05 for ; Wed, 4 Jan 2006 10:50:35 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.177]) by postgresql.org (Postfix) with ESMTP id 1B27C9DC9C9 for ; Wed, 4 Jan 2006 10:50:27 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu8) with ESMTP (Nemesis), id 0ML2ov-1Eu9yB2vzQ-0002Ff; Wed, 04 Jan 2006 15:50:32 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1Eu9yB-0003q2-00 for pgsql-sql@postgresql.org; Wed, 04 Jan 2006 15:50:31 +0100 Date: Wed, 4 Jan 2006 15:50:31 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: Regular Expression Matching problem... Message-ID: <20060104145030.GG3490@webserv.wug-glas.de> Mail-Followup-To: "A. Kretschmer" , pgsql-sql@postgresql.org References: <1136383726.8868.27.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1136383726.8868.27.camel@localhost.localdomain> X-DEST: 208 X-OS: Linux - weil ich es mir Wert bin! X-Info: registrierter Linux-User 97922 http://counter.li.org User-Agent: mutt-ng 1.5.9i (Linux) X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.492 required=5 tests=[AWL=0.492] X-Spam-Score: 0.492 X-Spam-Level: X-Archive-Number: 200601/15 X-Sequence-Number: 23804 am 04.01.2006, um 15:08:45 +0100 mailte Mario Splivalo folgendes: > I have a table containing regular expresion patterns for matching phone > numbers with the mobile operators. > > For instance, my phone number is '+385911234567', and the regexp for > this mobile operator is: "^\+38591\d{7}$". > > Now, when I do a regexp match in a single select, it behaves as > expected: > > octopussy2=# select '+385911234567' ~ '^\\+38591\\d{7}$'; > ?column? > ---------- > t > (1 row) > > Now, as I've mentioned, I have a table with operators and their patterns > for phone numbers: > > octopussy2=# select * from operators; > operator_id | operator_name | operator_phonenumber_pattern > -------------+---------------+------------------------------ > 1 | FreeSMSC | ^\\+38590\\d{6,7}$ > 2 | VipNet | ^\\+38591\\d{7}$ > 3 | T-Mobile | ^\\+3859[9|8]\\d{6,7}$ > 4 | Tele2 | ^\\+38595\\d{7}$ > (4 rows) > > > Now, if I construct my query like this: > > octopussy2=# select '+385911234567', operator_phonenumber_pattern, > '+385911234567' ~ operator_phonenumber_pattern from operators; > > ?column? | operator_phonenumber_pattern | ?column? > ---------------+------------------------------+---------- > +385911234567 | ^\\+38590\\d{6,7}$ | f > +385911234567 | ^\\+38591\\d{7}$ | f > +385911234567 | ^\\+3859[9|8]\\d{6,7}$ | f > +385911234567 | ^\\+38595\\d{7}$ | f > (4 rows) > > > Why do I get all the "f"'s? I tought that the operator_id 2 should > return "t", esp. when I wrote the first query it seems that the regex > match was ok. Try this: test=# select '+385911234567', operator_phonenumber_pattern, '+385911234567' ~ replace(operator_phonenumber_pattern,'\\\\','\\') from operators; ?column? | operator_phonenumber_pattern | ?column? ---------------+------------------------------+---------- +385911234567 | ^\\+38590\\d{6,7}$ | f +385911234567 | ^\\+38591\\d{7}$ | t +385911234567 | ^\\+3859[9|8]\\d{6,7}$ | f +385911234567 | ^\\+38595\\d{7}$ | f (4 rows) HTH, Andreas -- Andreas Kretschmer (Kontakt: siehe Header) Heynitz: 035242/47212, D1: 0160/7141639 GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net === Schollglas Unternehmensgruppe ===