in reply to How to format such a string?

s/(([io])+M)M*([io]*)(?=[io])/"$2$+[1]-$-[3]"/ge;