I'm trying to run a function taking as a parameter the matching criteria of a replace call, but I'm struggling with it. In the scenario of:
x="foo OFFSET_5 bar";
regex=/OFFSET_(-?[0-9]*)\b/g;
function timesThree(n){ return n*3 }
If I do a simple x.replace(regex, '$1') the output is, as expected, foo 5 bar.
However, I want to pass that 5 to timesThree, I'm unable to, getting always NaNinstead of 15.
I tried x.replace(regex, timesThree($1)), but to no avail.
Where is my code failing?
Thanks in advance
timesThree(parseInt(x.split("_")[1]))replace.