in reply to Regexp to extract HTML link data
I dunno, this didnt seem to be too dificult, so I have a feeling ive gone wrong here somewhere. But heres my go.
use strict; use warnings; foreach ('<td><img src="foo.jpg">'. '<a href="index3.html">New index</a></td>', '<td><a href="index3.html">New index</a></td>') { if (/<td>(?:<img[ ]src="([^"]+)">)? <a[ ]href="([^"]+)">((?:(?!<\/a>).)*) <\/a>/six) { print "Matched!\tImg=", ($1 ? $1 : 'None'), "\tLink: $2\t Link Text: $3\n"; } }
sorry about the weird look of the code its mostly like that to fit average settings on the site.
|
|---|