开发者

Javascript regex to match html comments, excluding those inside <style> tags

开发者 https://www.devze.com 2023-03-16 13:12 出处:网络
I need to get html comments ( <!-- --> ) except for those insidetags, which are used sometimes.

I need to get html comments ( <!-- --> ) except for those inside tags, which are used sometimes.

<style type="text/css">
<!--
.test { font-size: 12px; }
-->
</style>

Getting html comments is quite easy with this regex:开发者_如何学C

/<!--[^>]*-->/gi

The issue is that i can't exclude those that are inside tags. I tried:

(?!<style[^>]>)

but it still get the html comment. Any ideas?

Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号