#!/bin/bashs="B'10' AB'1010' B'1010101010'"sed -E ":a; s/(\bB'(12)*)10((10)*')/\112\3/g; t a" <<< "$s"
Standard input is empty
B'12' AB'1010' B'1212121212'
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!