所以我试图创建一个匹配不同类型的html标签内的文本的正则表达式。它应该与以下两种情况中的粗体文本相匹配:
<div class="username_container">
<div class="popupmenu memberaction">
<a rel="nofollow" class="username offline " href="http://URL/surfergal.html" title="Surfergal is offline"><strong><!-- google_ad_section_start(weight=ignore) -->**Surfergal**<!-- google_ad_section_end --></strong></a>
</div>
<div class="username_container">
<span class="username guest"><b><a>**Advertisement**</a></b></span>
</div>
我尝试使用以下正则表达式而没有任何结果:
/<div class="username_container">.*?((?<=^|>)[^><]+?(?=<|$)).*?<\/div>/is
这是我第一次在stackoverflow上发帖,所以如果我做了一些非常愚蠢的事我只能道歉。
答案 0 :(得分:0)
使用正则表达式解析html很难。请参阅评论中的链接。
您打算如何处理这些比赛?这是一个快速的jquery脚本,用于在控制台中记录结果:
var a = [];
$('strong, b').each(function(){
a.push($(this).html());
});
console.log(a);
结果:
["<!-- google_ad_section_start(weight=ignore) -->**Surfergal**<!-- google_ad_section_end -->", "<a>**Advertisement**</a>"]