Fix gsub errors. Fix #1734
Merge pull request #1812 from hawkthorne/fix_gsub

Fix gsub errors. Fix #1734