Why does echo ,,, |sed s':\(,\)\(,\):\1*\2:'g yield ,*,, rather than ,*,*,?  In other words: why, despite the g flag, does sed not insert '*' between one pair of commas?
Execution cycle of sed s/REGEXP/REPLACEMENT/g
sed;regular expression
Because with the two ,s in (,\)\(,\), you have already matched the first two ,s and the Regex pattern matched so far won't backtrack for the rest of the line. Only one is left now that is the last , hence it just printed as it is without any * in between it the second last one.If you have another , in input, you would get the desired (global, g) response:% echo ,,,, | sed s':\(,\)\(,\):\1*\2:'g,*,,*,