This needs to be a bit more robust. What about escaping percentage signs? Which characters are allowed in replacement keys?