I have a string such as
var string = 'blabla <a href="http://www.url.com" <custom-tag>attribute-x="blabla"</custom-tag>>an url</a> blabla <custom-tag>blabla</custom-tag> blablabla between tags <custom-tag><a href="http://www.anotherurl.com">blabla</a></custom-tag>';
where I want to strip all the custom-tag tags. The problem is that the deletion needs to happen sequential (I think) as multiple instances occur and the tag can contain other tags or be included in other tags itself.
At the moment, the best solution I have is
var deleteTag = '<custom-tag>.*<\/custom-tag>';
string= string.replace(new RegExp(deleteTag , 'g'), '');
which leaves me with
blabla <a href="http://www.url.com"
instead of
blabla <a href="http://www.url.com">an url</a> blabla blablabla between tags
Should I implement a loop or is there a way to do this with RegExp?
Thanks!
PS: It is not possible for me to parse my string as HTML as it contains tags within tags and would thus render false HTML (it is part of a templating module in our software so the string goes through some iterations after which it eventually does end up as HTML). So it is not a duplicate of questions such as Remove specific HTML tag with its content from javascript string