Don't forget the $replace(%babelu,%,% $+ 25) before doing the while with $regex, since % is also a character that needs to be converted to %25. This conversion must be done before other conversions, for obvious reasons.