use a for loop rather than complex regex/reversing/replacing