html - How to remove empty comma from string using JQuery -


i want remove empty commas string using jquery. please see attached images see mean.

enter image description here

enter image description here

this remove unnecessary commas in text , update text value:

$('.dyn-').text($('.dyn-').text().replace(/^,*|,(?=,)|,$/g, '')); 

the regex in 3 parts, seperated |:

  1. first part catches commas in beginning of string, since come before word, unnecessary,
  2. second part catches commas followed comma, last of repeating commas stay,
  3. and third part catches comma @ end of string, unnecessary.

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -