0
下面我有html content
來從DIV所有的錨標記文字從我希望獲取anchor tag
如何使用正則表達式
<div class="row mb-xlg"><div class="col-md-12">
<div class="heading heading-border heading-middle-border"><h3>Compatible Models</h3></div>
<div class="row show-grid">
<div class="col-md-4"><a href="/model/SFSPC19S80/_/_/Sanyo/PC19S80/" title="Sanyo PC19S80 Remote Control (Pc-27s80)">PC19S80</a></div>
<div class="col-md-4"><a href="/model/SFSPC25580/_/_/Sanyo/PC25580/" title="Sanyo PC25580 Remote Control (Pc-27s80)">PC25580</a></div>
<div class="col-md-4"><a href="/model/SFSPC25S80/_/_/Sanyo/PC25S80/" title="Sanyo PC25S80 Remote Control (Pc-27s80)">PC25S80</a></div>
<div class="col-md-4"><a href="/model/SFSPC27S80/_/_/Sanyo/PC27S80/" title="Sanyo PC27S80 Remote Control (Pc-27s80)">PC27S80</a></div>
</div></div></div>
之間的所有文字我有以下的正則表達式返回anchor tag
<a[^>]*>([^<]+)<\/a>+
之間的所有文本
測試在this website
結果 -
Full match `<a href="/model/SFSPC25580/_/_/Sanyo/PC25580/" title="Sanyo PC25580 Remote Control (Pc-27s80)">PC25580</a>`
Group 1. `PC25580`
Match 3
Full match `<a href="/model/SFSPC25S80/_/_/Sanyo/PC25S80/" title="Sanyo PC25S80 Remote Control (Pc-27s80)">PC25S80</a>`
Group 1. `PC25S80`
Match 4
Full match `<a href="/model/SFSPC27S80/_/_/Sanyo/PC27S80/" title="Sanyo PC27S80 Remote Control (Pc-27s80)">PC27S80</a>`
Group 1. `PC27S80`
但我想添加像
<h3>Compatible Models<\/h3>.*?<a[^>]*>([^<]+)<\/a>+
Compatible Models
字條件在這種情況下它只會返回第一錨標記的結果。 如何獲得所有錨點標記文本結果並存儲在array
如何得到與DOM解析器相同的結果。你能解釋一下嗎? – John