html - How to remove empty comma from string using JQuery -
i want remove empty commas string using jquery. please see attached images see mean.
this remove unnecessary commas in text , update text value:
$('.dyn-').text($('.dyn-').text().replace(/^,*|,(?=,)|,$/g, ''));
the regex in 3 parts, seperated |
:
- first part catches commas in beginning of string, since come before word, unnecessary,
- second part catches commas followed comma, last of repeating commas stay,
- and third part catches comma @ end of string, unnecessary.
Comments
Post a Comment