Skip site navigation (1) Skip section navigation (2)

Re: How to extract a substring using Regex

From: Mark Cave-Ayland <mark(dot)cave-ayland(at)ilande(dot)co(dot)uk>
To: Postgres User <postgres(dot)developer(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to extract a substring using Regex
Date: 2007-08-24 05:31:58
Message-ID: 1187933518.5655.24.camel@mca-desktop (view raw or flat)
Thread:
Lists: pgsql-general
On Thu, 2007-08-23 at 19:08 -0700, Postgres User wrote:
> On 8/23/07, Michael Glaesemann <grzm(at)seespotcode(dot)net> wrote:
> >
> > On Aug 23, 2007, at 20:01 , Postgres User wrote:
> >
> > >>> Yes, I read the manual.  I think I had a problem because of the
> > >>> special chars (< / >) that I'm trying to search for...  Still
> > >>> looking
> > >>> for the right syntax.
> > >>
> > >> Why don't you show us what you've tried and the errors you're
> > >> getting? That way we can help you figure out what you're doing wrong
> > >> rather than just give you an answer.
> > >>
> > >> Michael Glaesemann
> > >
> > > SELECT substring(data_field from '<name>(.)</name>')
> > > FROM myTable
> >
> > Looks like you might want to brush up on regular expressions in
> > general. Your expression will match a single character between the
> > <name> tags. You might want to try something like .+ instead.
> >
> > Michael Glaesemann
> 
> You're right, that was a typo, I didn't copy and paste.
> I found the problem, I was using 2 forward slashes instead of a
> backslash + forward slash when pattern matching.  The correct regex to
> extract my substring:
> 
> substring(data_field from '<name>(.+)<\/name>')

FWIW, I find the following site extremely useful when trying to create
moderately complex regular expressions: http://www.rexv.org.


HTH,

Mark.

-- 
ILande - Open Source Consultancy
http://www.ilande.co.uk



In response to

Responses

pgsql-general by date

Next:From: Magnus HaganderDate: 2007-08-24 06:08:44
Subject: Re: FATAL: could not reattach to shared memory (Win32)
Previous:From: Tom LaneDate: 2007-08-24 03:27:05
Subject: Re: FATAL: could not reattach to shared memory (Win32)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group