Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • How to get the string after last comma in java?
  • get all characters after “,” character
like image 610
Mithun Sreedharan Avatar asked Dec 11 '22 18:12

Mithun Sreedharan


1 Answers

Simple:

str = str.replace(/,[^,]+$/, "")
like image 137
Aidas Bendoraitis Avatar answered Feb 09 '23 00:02

Aidas Bendoraitis