Re: back references using regex - Mailing list pgsql-general

From Michael Fuhr
Subject Re: back references using regex
Date
Msg-id 20050910132338.GB45586@winnie.fuhr.org
Whole thread Raw
In response to Re: back references using regex  (Matthew Peter <survivedsushi@yahoo.com>)
List pgsql-general
On Fri, Sep 09, 2005 at 10:11:46PM -0700, Matthew Peter wrote:
> One other thing, when I wrote back I actually used
> 34.31.29.20 (random), not 12.00.00.34 like i showed in
> the example, which is why i said it didn't work on
> digits.

When posting examples, please post something you actually tried so
other people can see exactly what you're doing and attempt to
duplicate your results.  Little differences sometimes matter, as
this case illustrates.

> SELECT substring('34.31.29.20' FROM $$((\w+)\.\2)$$);
>   substring
>  -----------
>
>  (1 row)
>
> little did i know writing it with 12.00.00.34 would
> return 00.00... so yes, that did suprise me.
> Apparently only using the identical values returns a
> value.

That's what a back reference is: it means "match the same value you
matched before," not just anything that matches the same regular
expression.

Usenet junkies might find it amusing to use back references to
search their new server's list of newsgroups:

egrep '([^.]+)\.\1\.\1' newsgroups

--
Michael Fuhr

pgsql-general by date:

Previous
From: Douglas McNaught
Date:
Subject: Re: back references using regex
Next
From: Tom Lane
Date:
Subject: Re: ERROR: type "temp_gc" already exists