In JS, I can use a function String.prototype.replace() when replacing a submatch in a regular expression. For example:
var x = 'a1b2c3'.replace(/(\d+)/g, (num) => {
return num*num+1
})
console.log(x)
// 'a2b5c10'
I've tried using sed but it seems that invoking an operator $(()) inside of the replacement is not possible.
$ echo "a1b2c3" | sed 's/\([^0-9]*\)\([0-9]\)\([^0-9]*\)/\1$((\2*\2+1))\3/g'
# Output: a$((1*1+1))b$((2*2+1))c$((3*3+1))
Is there a similar tool or function in bash that has the functionality similar to JS's String.replace()?