in reply to Making multiple replaces through Regex

If iterations are ok for you, then try the following..
if(/<csp c="(\d+)">/) { $number= 1; $iteration = $1; $string .= '<colspec colnum="'. $number . '" colname="col' . $number+ ++ . '"/>' while ( $iteration-- ); } print $string;
code is, first check whether format given is right, if it is then use some temporary variables, and do the string concatenation with the help of it.