5

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

For example if i input Vettucaud, Thiruvananthapuram, Kerala, India,last word India should be removed and the output need tro be like Vettucaud, Thiruvananthapuram, Kerala

Exactly the reverse thing in

Community
  • 1
  • 1
Mithun Sreedharan
  • 49,883
  • 70
  • 181
  • 236

1 Answers1

14

Simple:

str = str.replace(/,[^,]+$/, "")
Aidas Bendoraitis
  • 3,965
  • 1
  • 30
  • 45