我有一个html页面作为字符串,如下所示, "<div id="app"> <section> <esi:include src="http://example.com/LICENSE" /> </section> <section> <esi:include src="http://test.com/LICENSE" /> </section> </div>"从上面的字符串中,需要提取所有esi标签(src的值将是动态的)。所以我需要正则表达式来提取所有匹配的标签。以 开头和结尾的示例正则表达式。<esi:include/>预期输出为,[<esi:include src="http://example.com/LICENSE" />, <esi:include src="http://test.com/LICENSE" />]
1 回答

胡子哥哥
TA贡献1825条经验 获得超6个赞
请尝试以下解决方案:
str = new String('<div id="app"><section><esi:include src="http://example.com/LICENSE" /></section><section><esi:include src="http://test.com/LICENSE" /></section></div>');
array = str.match(/<esi:include(\s+(.*?)\s*\/>)/g);
console.log(array);
添加回答
举报
0/150
提交
取消