Call gsub with a Regexp instead of a String for better performance

Benchmarks are here: #17308