I would like to remove unknown substring when it occurs between two known substring ( <foo>and </foo>). For example, I would like to convert:
hello <foo>remove me</foo>
at
hello <foo></foo>
I can do it with
s = ...
s.replace(/<foo>.*?<\/foo>/, '<foo></foo>')
but I would like to know whether there is a way to do this without repeating known substring ( <foo>and </foo>) in the regular expression and replacement text.
source
share