admin管理员组文章数量:1418400
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.
本文标签: Remove word after last dash with regex in JavaScriptStack Overflow
版权声明:本文标题:Remove word after last dash with regex in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745274901a2651122.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论