Marco Pietrosanto
Marco Pietrosanto

Reputation: 420

grep for html what's wrong?

<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

Answers (2)

Kouber Saparev
Kouber Saparev

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

mrVoid
mrVoid

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

Related Questions