being smarter about the regexp replacements