Mithun Sreedharan
Mithun Sreedharan

Reputation: 51274

How to remove every thing after last comma character in a string?

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

Upvotes: 5

Views: 6138

Answers (1)

Aidas Bendoraitis
Aidas Bendoraitis

Reputation: 4003

Simple:

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

Upvotes: 14

Related Questions