Re: How to extract a substring using Regex - Mailing list pgsql-general

From Postgres User
Subject Re: How to extract a substring using Regex
Date
Msg-id b88c3460708231908x6d1a1192yf41e31475f47b37d@mail.gmail.com
Whole thread Raw
In response to Re: How to extract a substring using Regex  (Michael Glaesemann <grzm@seespotcode.net>)
Responses Re: How to extract a substring using Regex  (Michael Glaesemann <grzm@seespotcode.net>)
Re: How to extract a substring using Regex  (Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>)
List pgsql-general
On 8/23/07, Michael Glaesemann <grzm@seespotcode.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>')

pgsql-general by date:

Previous
From: "Postgres User"
Date:
Subject: Simple Regex question, hoping for direct answer (no Socratic approach necessary)
Next
From: Michael Glaesemann
Date:
Subject: Re: How to extract a substring using Regex