I highly recommend giving "gema" a look.
It is one of the quite obscure yet superb ways of transforming text, surpassing the readability and the efficiency of regular expressions by an odd margin.
https://gema.sourceforge.net/new/gema_man.shtml
It is one of my biggest discoveries of the last months.