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 B031E9FA0EC for ; Fri, 7 Jul 2006 13:00:42 -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 13065-01-8 for ; Fri, 7 Jul 2006 13:00:36 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.ringways.co.uk (host-80-193-83-141.static.telewest.net [80.193.83.141]) by postgresql.org (Postfix) with ESMTP id 747549FB214 for ; Fri, 7 Jul 2006 13:00:25 -0300 (ADT) Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.62) (envelope-from ) id 1Fysjd-0006Lp-JZ for pgsql-sql@postgresql.org; Fri, 07 Jul 2006 16:59:17 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Re: SELECT substring with regex Date: Fri, 7 Jul 2006 16:59:14 +0100 User-Agent: KMail/1.9.1 References: <44AE66E0.1040606@numerixtechnology.de> In-Reply-To: <44AE66E0.1040606@numerixtechnology.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200607071659.14940.gary.stainburn@ringways.co.uk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/105 X-Sequence-Number: 25679 On Friday 07 July 2006 14:51, T E Schmitz wrote: > I would like to split the contents of a column using substring with a > regular expression: > > SELECT > substring (NAME, '^\\d+mm') as BASE_NAME, > substring (NAME, ??? ) as SUFFIX > FROM MODEL > > The column contains something like > "150mm LD AD Asp XR Macro" > I want to split this into > "150mm", "LD AD Asp XR Macro" > > How can I extract the bit following the matching substring? select substring('150mm LD AD Asp XR Macro','^\\d+mm') as BASE_NAME, substring('150mm LD AD Asp XR Macro','^\\d+mm (.*)$') as SUFFIX; base_name | suffix -----------+-------------------- 150mm | LD AD Asp XR Macro (1 row) The brackets surround the required match -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000