I want to remove certain characters when they are at the end of a string. I have a working regex but the issue is the following:
My code:
var text = "some string";
text.replace(/\,$|:$|;$|-$|\($|–$|#$|\.$/, '');
So let's see the issue
If text = "that a nice (
", then my code outputs "that a nice "
, which is exactly what I want.
But if if text has multiple matches such as
text = "that a nice ( #"
, then the output of my current code is: "that a nice ( "
... but I want to remove also the (
when it's at the end of the string as you can see on my regexp. I'd need to trim it so that the white space is removed but then how to remove the ( again...
The question is how to remove any unwanted characters and make sure that the new output also does not include these characters at their (new) end ? I could have 2, 3 or whatever number of unwanted characters at the end