Reputation: 103
I’ve defined string word-word-word-test
and I want to remove the -test
(all behind the last dash). How can I do that with a RegEx?
My /-.*$/
works only if there are no other dashes in the string.
Upvotes: 2
Views: 2616
Reputation: 191749
You can use -[^-]*$
to replace "dash followed by zero or more non-dash characters anchored to the end of the string." You may also just want to use (-test)*$
to replace all -test
instances at the end of the string.
Upvotes: 8