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
  • 47,989
  • 69
  • 178
  • 233

1 Answers1

14

Simple:

str = str.replace(/,[^,]+$/, "")
Aidas Bendoraitis
  • 3,805
  • 1
  • 31
  • 44