javascript - How to separate comma in js -


my input string below:

in|1st cross,1st block,in|282,sector 19,in|10th floor,winchester house,dn|id,fgh,fg|ag 

what want should like:

in|1st cross,1st block in|282,sector 19 in|10th floor,winchester house dn|id,fgh fg|ag 

please how achieve above result?

there go:

function separatecomaforcountry(str) {     // find coma, has amount of letters after not , nor | , stop when see either end of string or |      var reg = /,([^|,]+(?:$|\|))/g;     return str.replace(reg, function(match, country){         return ' ' + country;     }); } 

then call function use case.

separatecomaforcountry("in|1st cross,1st block,in|282,sector 19,in|10th floor,winchester house,dn|id,fgh,fg|ag"); // outputs in|1st cross,1st block in|282,sector 19 in|10th floor,winchester house dn|id,fgh fg|ag 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -