2021年4月25日星期日

Regex remove comma and space at the last character only

I'm a newbie with regex.. I've tried to remove comma and space , at the last character like this.

this is my string

var str = Gang Cipicung 7, Kebon Gedang, Kecamatan Batununggal,   

this is my regex

str.replace(/[, ]+/g, " ").trim()  

this is my expect

Gang Cipicung 7, Kebon Gedang, Kecamatan Batununggal  

how can I deal with it, Thanks in advance

https://stackoverflow.com/questions/67260696/regex-remove-comma-and-space-at-the-last-character-only April 26, 2021 at 12:03PM

没有评论:

发表评论