X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 01555D1D1E6 for ; Wed, 20 Aug 2003 03:50:55 -0300 (ADT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 44587-02 for ; Wed, 20 Aug 2003 03:50:33 -0300 (ADT) Received: from news.hub.org (unknown [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id 5CECED1B982 for ; Wed, 20 Aug 2003 03:50:32 -0300 (ADT) Received: from news.hub.org (host-64-117-224-194.altec1.com [64.117.224.194] (may be forged)) by news.hub.org (8.12.9/8.12.9) with ESMTP id h7K6oWek041769 for ; Wed, 20 Aug 2003 06:50:32 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h7K6jDu4040910 for pgsql-sql@postgresql.org; Wed, 20 Aug 2003 06:45:13 GMT From: "Moonstruck" X-Newsgroups: comp.databases.postgresql.sql References: <3f407aa4$0$15136$afc38c87@news.optusnet.com.au> <200308181611.27937.josh@agliodbs.com> Subject: Re: Reverse pattern match. Date: Wed, 20 Aug 2003 16:42:30 +1000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 Lines: 63 Message-ID: <3f431856$0$15134$afc38c87@news.optusnet.com.au> To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/240 X-Sequence-Number: 14856 Many thanks... got it now. Example... sox=# select * from regexpatt; pattern | description ---------+------------------------------------ ^b | starts with a B ^a | starts with an A ^c.*l$ | starts with a C and ends with an L (3 rows) sox=# select description from regexpatt where 'bravo' ~ pattern; description ---------------- starts with a B (1 row) sox=# select description from regexpatt where 'caramel' ~ pattern; description ------------------------------------ starts with a C and ends with an L (1 row) "Josh Berkus" wrote in message news:200308181611.27937.josh@agliodbs.com... Moonstruck, > I want to create a table of regular expression patterns (for assessing > phone numbers), something like: > CREATE TABLE CallType ( pattern varchar primary key, > type varchar, > rate int4); > INSERT INTO CallType VALUES ('0[3-9]________','Interstate Call',50); > INSERT INTO CallType VALUES ('9_______','Local Call',25); > INSERT INTO CallType VALUES ('0011__________%','International Call',100); PostgreSQL supports real Regular Expressions, via the ~ operator. See "~" under "functions and operators", and then consult your favorite book or online ressouce on how to compose regexps. An example of "is not in 415 area code" would be phone_no ~ '^415\d{7}' which should be "415" at the beginning followed by at least 7 other digits. (Folks, please correct my regex code if it's bad!) The disadvantage to this approach is that it cannot be indexed. -- -Josh Berkus Aglio Database Solutions San Francisco ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html