Javascript - remove last one with global modifier not working
2 answers
You need to use quantifier with your character class. Ratio +
means "one or more" times. Also you can avoid escaping certain characters inside your class and remove the global modifier.
'2*****'.replace(/[-+*/]+$/, '') //=> "2"
Explanation:
[-+*/]+ # any character of: '-', '+', '*', '/' (1 or more times)
$ # before an optional \n, and the end of the string
+6
source to share