pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rodrigo De Leon <rdeleonp@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: SELECT substring with regex
Date: Fri, 7 Jul 2006 20:24:07 -0500
Message-ID: <a55915760607071824k65a09b3ahd52b16bdd59108b8@mail.gmail.com> (raw)
In-Reply-To: <44AEB4C6.9000903@numerixtechnology.de>
References: <44AE66E0.1040606@numerixtechnology.de>
	<200607071659.14940.gary.stainburn@ringways.co.uk>
	<44AE9B4F.1020401@numerixtechnology.de>
	<a55915760607071137q2c70346cp5b30cac14beaf1e7@mail.gmail.com>
	<44AEB4C6.9000903@numerixtechnology.de>

On 7/7/06, T E Schmitz <mailreg@numerixtechnology.de> wrote:
> Sorry, but that would also capture something like
> 10-30-59mm
>
> The pattern describes either a single length (120 millimeters) or a
> range (30 to 70 millimetres), hence:
>
> \\d+(-\\d+)?mm
>
> The ? quantifier refers to the combination of '-' and digits and has to
> be bracketed.
>
> ...
>
> Still, I'd be interested to know whether there is a 'more elegant' solution.

OK, last try using regex:

SELECT
NAME
, substring(NAME, '^(\\d+(-\\d+)?mm)') AS BASE_NAME
, regexp_replace(NAME, '^\\d+(-\\d+)?mm (.*)', '\\2') AS SUFFIX
FROM MODEL

Regards,

Rodrigo



view thread (20+ messages)  latest in thread

Message-ID: <a55915760607071824k65a09b3ahd52b16bdd59108b8@mail.gmail.com>
Permalink:  ../a55915760607071824k65a09b3ahd52b16bdd59108b8@mail.gmail.com/
Also on:    postgresql.org/message-id/a55915760607071824k65a09b3ahd52b16bdd59108b8@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rdeleonp@gmail.com
  Subject: Re: SELECT substring with regex
  In-Reply-To: <a55915760607071824k65a09b3ahd52b16bdd59108b8@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox