一个插入sql语句,要求用正则表达式把语句中形如’2023-12-26’形式的部分替换为形如to_date(‘2023-12-26’)的内容,代码实例:
function regReplace(str) {
const pattern = /'([0-9]*)-([0-9]*)-([0-9]*)'/g;
while ((match = pattern.exec(str)) !== null) {
console.log("match", match);
const origin = `'${match[1]}-${match[2]}-${match[3]}'`;
const target = `to_date('${match[1]}-${match[2]}-${match[3]}')`;
str = str.replace(origin,target);
console.log("str", str);
}
return str;
}