Re: SELECT substring with regex

From: "Rodrigo De Leon" <rdeleonp(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: SELECT substring with regex
Date: 2006-07-08 01:24:07
Message-ID: a55915760607071824k65a09b3ahd52b16bdd59108b8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On 7/7/06, T E Schmitz <mailreg(at)numerixtechnology(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Glaesemann 2006-07-08 04:17:12 Re: Atomar SQL Statement
Previous Message Aaron Bono 2006-07-07 22:39:47 Re: SELECT substring with regex