0
var ad_pop="Floor 19, , 43 Varick Street, New York, NY" 

Tried this. but didn't work.

alert(ad_pop.replace(/[, ]+/g, " ").trim());

expected output:

Floor 19, 43 Varick Street, New York, NY
trincot
  • 317,000
  • 35
  • 244
  • 286
has
  • 1
  • https://stackoverflow.com/questions/2823016/regular-expression-for-duplicate-words looks helpful. --- Try using the regex `/(, +)\1/g` replacing with `$1`? – evolutionxbox Dec 02 '21 at 12:04
  • `replace(/,\W+,/g, ",")` - replace all commas that are followed by an arbitrary amount of whitespace and then another comma, with one single comma. – CBroe Dec 02 '21 at 12:04
  • Why is this tagged with jQuery? – trincot Dec 02 '21 at 12:06

0 Answers0