0
How to Use RegEx in JS to remove/replace "<tagname>" from a HTML Document?
I just want to remove opening tag of html element using JS' RegEx not its content(text)
4 ответов
+ 1
This migth work
var reg = /<.+?>/gi;
var text = "<tag>Hello world</tag>";
var here = text.replace(reg, "");
console.log(here);
0
Thanks it is working,
However It removes every tag in a page, how can i select a specific tag like
<a href.......................>, <div .......>?
Beauty
0
var reg = /<a.*?>/gi
0
Sorry not /<a.*?>/gi
Use this
/<[\/]{0,1}(a)[^><]*>/gi
This is example to remove a tag from string
/<[\/]{0,1}(div)[^><]*>/gi
This is example to remove div tag from string