var aa = new RegExp("([abcdefg]+)([12345678]+)", "ig"); var str = "aa123bb123cc45"; var bb = str.replace(aa, "$1888$2\r\n");