String#gsub fix with last character

Due to the reason that the current String#gsub implementation uses String#split it will forget to replace the last character in case it is a hit.