Answer the question
In order to leave comments, you need to log in
How to replace all minuses with underscores in a tag?
Good afternoon.
There is text in which you want to replace minuses with underscores. but only in those words that begin with a lattice. The number of minuses is not constant.
I assume that it should be a regular season with a look back, and there is a match, but how can I replace it?
Tell me how to do it? Perhaps the regular season is from a cannon on sparrows, and should it be done in a completely different way?
var msg = `foo-bar-bar (ssh://foo-bar-bar)
#PROBLEM #foo-bar-bar
foo-bar (ssh://foo-bar)
#PROBLEM #foo-bar
`
const regex = /(#[\w]*)(-(\w*)){1,}/ig;
console.log(msg.replace(regex, "\$1_\$3"));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question