• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

199
Views
How to remove only those commas which are present inside double quotes in a string?

The Current String (below)

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.

Expected output:

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.

Note

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).

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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);

almost 3 years ago · Juan Pablo Isaza Report

0

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.
almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error