当前字符串(如下)
153,Rajashekar,9/13/2021,06-01-1988,33%,NAD,不适用于新冠肺炎,NAD,NAD,患者“健康状况良好,准备出院”,10,Pale黄,清澈,Nil,Nil,双眼单纯性近视,正常,共同报告,正常,报告附件,WNL,“无控制高血压:盐限制饮食,定期行走,定期监测血压( 15天),心脏病专家的意见和进一步评估。关于视觉,建议玻璃处方远视。",*条件匹配,是的,可以工作。
预期产出:
153,Rajashekar,9/13/2021,06-01-1988,33%,NAD,不适用于新冠肺炎,NAD,NAD,“健康准备出院的病人”,10,Pale黄,清澈,Nil,Nil,双眼单纯性近视,正常报告,共享报告,正常报告,附加报告,WNL,“无控制高血压:定期盐限制饮食常规步行血压监测( 15天一次))心脏病专家的意见和进一步评估。关于视觉,建议玻璃配方远视。",*条件匹配,是的,可以工作。
备注
正如您所看到的,这个大字符串中有很多逗号,我只想从那些包含双引号的子字符串(粗体文本)中删除逗号。
发布于 2021-10-07 13:01:03
假设双引号总是平衡的,您可以尝试用回调函数替换regex:
var input = "A,B,\"foo, bar\",D";
var output = input.replace(/"(.*?)"/g, (x) => x.replace(/,/g, ""));
console.log(input);
console.log(output);
发布于 2021-10-07 13:05:01
const stringToClean = `153,Rajashekar B Hanchinal,9/13/2021,06-01-1988,33,M3249,M,9739465908,RIPL,Manufacturing Assistant,Starch,168,67,24,Normal Weight,B+Ve,160,100,76,93,88,A Small black mole present over the Rt.hand palm,8 Years,Vegetarian,NAD,Nil in particular,NAD,NAD,HTN,Nil in particular,No,98%,NAD,NAD,NAD,NAD,not applicable in view of covid-19,NAD,NAD,"Patient in good health, ready to discharge", Not in Particulars,10,Pale Yellow,Clear,Nil,Nil,Both eyes simple myopia,Normal,Reports Shared,Normal,Reports Attached,WNL, "Uncontrolled hypertension: Salt Restricted Diet, Regular walk, Monitor blood pressure regularly ( once in 15 days ), Cardiologist opinion with further evaluation. Pertain to vision, advised glass prescription distance vision. ", *Conditional Fit,Yes to work.`
const result = s.replace(/"[^"]+"/g, function(v) {
return v.replace(/,/g, '');
});
console.log(result) //153,Rajashekar B Hanchinal,9/13/2021,06-01-1988,33,M3249,M,9739465908,RIPL,Manufacturing Assistant,Starch,168,67,24,Normal Weight,B+Ve,160,100,76,93,88,A Small black mole present over the Rt.hand palm,8 Years,Vegetarian,NAD,Nil in particular,NAD,NAD,HTN,Nil in particular,No,98%,NAD,NAD,NAD,NAD,not applicable in view of covid-19,NAD,NAD,"Patient in good health ready to discharge", Not in Particulars,10,Pale Yellow,Clear,Nil,Nil,Both eyes simple myopia,Normal,Reports Shared,Normal,Reports Attached,WNL, "Uncontrolled hypertension: Salt Restricted Diet Regular walk Monitor blood pressure regularly ( once in 15 days ) Cardiologist opinion with further evaluation. Pertain to vision advised glass prescription distance vision. ", *Conditional Fit,Yes to work.https://stackoverflow.com/questions/69481555
复制相似问题