Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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

about 4 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.
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!