Reputation: 420
<a href=\"\/foo\/.*"\s>.*?<\/a>
to grep
<a href="/foo/thong" >Good</a><a href="/foo/thing" >Bad</a>
gives the whole line. What if I wanted to get the two separated matches? (all single matches between and )
Upvotes: 0
Views: 31
Reputation: 8105
Put the non-greedy option inside the href
argument as well.
preg_match_all('#<a href="/foo/.*?" >.*?</a>#', $str, $m);
print_r($m);
Upvotes: 1
Reputation: 995
Try:
echo '<a href="/foo/thong" >Good</a><a href="/foo/thing" >Bad</a>' |
sed 's/<a href=\"\/foo\/\([^\"]*\)\"\s>[^<]*<\/a>/\1\n/g'
Upvotes: 0