The problem was the second possible 15 converting without the first possible 15 should it be a 15. The solution is
"${string/#?15/${z/%15??/z}}"
, but then how can the first command "${string/%15/z}"
also be included in the same curly braces?
Code:
string="15151"; # wrong z151 / 15z1 / zz1 > should be unchanged
string="11515"; # correct 1z15 / 115z / 1zz > should be changed
echo ${string/%15/z}
echo ${string/#?15/${z/%15??/z}}