I want to add (int) value to a backreference.
For this I created a function and pass the appropriate backreference. The backreference if returned without any modification works fine, however when I try to modify or use any other functions on the backreference that was passed it assumes \3 as the argument value and not the backreference value itself.
For eg-
CREATE OR REPLACE FUNCTION add10(text) returns text as $$
DECLARE
t int;
BEGIN
t := to_number($1, '999999') + 10;
return trim(to_char(t, '999999'), ' ');
END;
$$ LANGUAGE plpgsql;
then:
select regexp_replace('890808', '80(\d+)', add10('\1'), 'g');
should give result as
test
-------
89018
(1 row)
However it gives --
test
-------
89011
(1 row)
taking the value of $1 as 1(the backreference number) instead of value 8.
Any ideas why does this happen?
add10()function enter?