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
Post a Comment