0

有如下代码:

<!--headTrap<body></body><head></head><html></html>-->
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">


        
        




        <link rel="dns-prefetch" href="//res.wx.qq.com">
<link rel="dns-prefetch" href="//mmbiz.qpic.cn">
<link rel="shortcut icon" type="image/x-icon" href="//res.wx.qq.com/mmbizwap/en_US/htmledition/images/icon/common/favicon22c41c.ico">


        <title>最新发布: 企业自主环保验收管理的指导意见!8种情况可通过验收,4种不予通过</title>
        


<!--[if lt IE 9]>
<link onerror="wx_loaderror(this)" rel="stylesheet" type="text/css" href="//res.wx.qq.com/mmbizwap/en_US/htmledition/style/page/appmsg/page_mp_article_improve_pc2c9cd7.css">
<![endif]-->
<body>
    <div>
        测试测试
    </div>
</body>

怎么通过正则将<!---->注释、meta标签、link标签都替换为""(空字符串)

1个回答

0

已采纳

最直观的写法

str.replace(/(<!--.*?-->)|(<meta.*?>)|(<link.*?>)/g, '')

稍微简化下

str.replace(/(<!--.*?-->)|(<(meta|link).*?>)/g, '')

撰写答案