Re: Emulating flexible regex replace - Mailing list pgsql-general

From David G Johnston
Subject Re: Emulating flexible regex replace
Date
Msg-id 1414079100688-5824046.post@n5.nabble.com
Whole thread Raw
In response to Emulating flexible regex replace  (twoflower <standa.kurik@gmail.com>)
Responses Re: Emulating flexible regex replace  (David G Johnston <david.g.johnston@gmail.com>)
List pgsql-general
twoflower wrote
> Source: 123 source text
> Target: 123 target text
> Source pattern: ([0-9]+) source text
> Target pattern: $1 target text
>
> Still, isn't there some super clever way to do that?

You use "\1" instead of "$1"

SELECT regexp_replace('123 abc','(\d+)\s(\w+)','\1 def'); --output: '123
def'

http://www.postgresql.org/docs/9.3/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP

9.7.3 - paragraph beginning "The regexp_replace function provides
substitution..."

David J.






--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Emulating-flexible-regex-replace-tp5824034p5824046.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Emulating flexible regex replace
Next
From: Francisco Olarte
Date:
Subject: Emulating flexible regex replace