How do I remove every thing after the last comma in a line?

With JavaScript, how can I remove every thing after the last coma in a string using regular expressions?

For example, if I was typing Vettucaud, Thiruvananthapuram, Kerala, India

, the last word India

should be removed and the output should be likeVettucaud, Thiruvananthapuram, Kerala

Exactly the opposite in

+3


source to share


1 answer


Plain:



str = str.replace(/,[^,]+$/, "")

      

+8


source







All Articles