PCRE: references to captures in replace string

Roberto Cornacchia roberto.cornacchia at gmail.com
Wed Apr 20 16:35:06 CEST 2016

After declaring a wrapper for pcre.replace:

sql>create function pcre_replace(s string, pattern string, repl string,
flags string) returns string external name pcre."replace";
operation successful (6.187ms)

I cannot get replacements with references to captures work (but the code in
pcre.c seems to support it):

sql>select pcre_replace('Apple Pear', '^([a-zA-Z]+)\\s*([a-zA-Z]+)$', '\\1
\\2', '');
| pcre_replace_single_value |
| \1 \2                     |
1 tuple (0.309ms)

The pattern is matched, but the back references are replaced literally.
Am I not getting the syntax correct?
>From http://www.pcre.org/original/doc/html/pcresyntax.html I see I could
use any of \1, \g1, \g{1] for back references, but none seem to work.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.monetdb.org/pipermail/users-list/attachments/20160420/f46daeb0/attachment.html>

More information about the users-list mailing list