153,Rajashekar,9/13/2021,06-01-1988,33,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.
153,Rajashekar,9/13/2021,06-01-1988,33,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.
As you can see there are lots of commas in this big string, I want to remove commas from only those sub-strings which contain double quotes here (in bold text).
Assuming the double quotes would always be balanced, you could try a regex replacement with a callback function:
var input = "A,B,\"foo, bar\",D";
var output = input.replace(/"(.*?)"/g, (x) => x.replace(/,/g, ""));
console.log(input);
console.log(output);
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.