Re: Substring question

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Adam Witney <awitney(at)sghms(dot)ac(dot)uk>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Substring question
Date: 2004-12-13 18:41:02
Message-ID: 20041213184102.GA79558@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Dec 13, 2004 at 06:17:27PM +0000, Adam Witney wrote:
>
> I am trying to select a part of a text field based on a regular expression,
> the data looks like this
>
> Rv0001c_f
> Rv0002_r
> Rv1003c_r
>
> Etc
>
> I would like to be able to select like this (this is a regular expression I
> would do in perl)
>
> SELECT substring(primer_name, '(\w+)\d\d\d\d[c]*_[fr]$') from primer;

The "POSIX Regular Expressions" section in the manual contains the
following note:

Remember that the backslash (\) already has a special meaning in
PostgreSQL string literals. To write a pattern constant that
contains a backslash, you must write two backslashes in the
statement.

SELECT substring(primer_name, '(\\w+)\\d\\d\\d\\d[c]*_[fr]$') FROM primer;
substring
-----------
Rv
Rv
Rv
(3 rows)

Is that what you're after?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Josh Berkus 2004-12-13 18:43:28 Re: pg_restore taking 4 hours!
Previous Message Janning Vygen 2004-12-13 18:37:41 Re: table with sort_key without gaps