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.
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.
-
What language are you using? The regex is mostly language-independent (something like
-[^-]*$
), but the mand to execute the replacement is language-dependent. – elixenide Commented Jan 27, 2014 at 1:23
1 Answer
Reset to default 8You 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.