var otherCode = '<link rel="icon" href="1.css" />'+
'<style> .test{color: #fff;} </style>'+
'<script>console.log(2)</script><script id="s_js_news">console.log(3)</script>';
var linkReg= /<link(.*?)\/>/gi;
var styleReg= /<style(.*?)>(.*?)<\/style>/gi;
var scriptReg= /<script(.*?)>(.*?)<\/script>/gi;
var linkResult = otherCode.match(linkReg) || []
var styleResult = otherCode.match(styleReg) || []
var scriptResult = otherCode.match(scriptReg) || []
console.log(linkResult)
console.log(styleResult)
console.log(scriptResult)
实例
结果
网友评论