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)

19th Oct 2021, 2:22 PM
Mohammed Azam
4 ответов
+ 1
This migth work var reg = /<.+?>/gi; var text = "<tag>Hello world</tag>"; var here = text.replace(reg, ""); console.log(here);
19th Oct 2021, 2:36 PM
Pariket Thakur
Pariket Thakur - avatar
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
20th Oct 2021, 2:00 PM
Mohammed Azam
0
var reg = /<a.*?>/gi
20th Oct 2021, 2:38 PM
Pariket Thakur
Pariket Thakur - avatar
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
20th Oct 2021, 2:48 PM
Pariket Thakur
Pariket Thakur - avatar