try this instead `contents = contents.replace( /"([^"]*)?\.js"/g, "\"$1.min.js\"" )`