正则捕获,转换时间格式:
const str ='20210426141823';
const s = str.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/,(_,...args)=>{
const[year, month, day, h, d, s]= args;
return`${year}年${month}月${day} ${h}时${d}分${s}秒`
});
console.log(s);
// 2021年04月26 14时18分23秒