in reply to 3 capture multi line regex
Just modify the style names in the qr'ed regex and use it.#!usr/bin/perl my $html = <<'HTML'; <li><a class="style5" href="http://www.site.com/page.html"> some words here</a> - <a class="style3" href="http://www.site.com/page2.html"> "some words here"</a> </li> HTML my $regex = qr{ <a \s+ class\s*=\s*"style5" \s+ href\s*=\s*[\"\'] [^\"\']+ [\"\']\s*> #first href (not c +aptured) \s*([^<>]+?)\s* #text inside first <a></a> +(captured) </a>\s* -\s* <a \s+ class\s*=\s*"style3" \s+ href\s*=\s*[\"\'] ([^\"\']+) [\"\']\s*> #second href (not +captured) \s*([^<>]+?)\s* #text inside second <a></a> + (captured) </a> }xi; $html =~ /$regex/; print join "\n", $1, $2, $3, "";
But if you want something more than a one-time solution for a very certain case, it'll be better to study HTML parsing modules mentioned in the comment above.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 3 capture multi line regex
by Anonymous Monk on Jun 30, 2006 at 18:23 UTC | |
by Ieronim (Friar) on Jun 30, 2006 at 18:44 UTC | |
by Anonymous Monk on Jun 30, 2006 at 20:34 UTC | |
by Ieronim (Friar) on Jun 30, 2006 at 21:40 UTC | |
by Anonymous Monk on Jun 30, 2006 at 22:28 UTC |