kachunyu has asked for the wisdom of the Perl Monks concerning the following question:
where I want to find and print "earth_text". This I can do with a one liner:<div><ul class="test"> <li><a href="/www/?category=Earth">earth_text</a></li></div>
However the file also has cases where there are multiple entries; for example:perl -lne 'BEGIN{undef $/} while (/<div><ul class="test">.*?<li><a hre +f=\"\/www\/\?category=.*?\">(.*?)<\/a><\/li></div>/sg){print $1}' ind +ex.html
Is there a way to find one or multiple instances of <li>...</li>? That is, since they are associated with the same code block, I want perl to return $1="earth_text" and $2="space_text" in the above example and spit out the text like:<div><ul class="test"> <li><a href="/www/?category=Earth">earth_text</a></li> <li><a href="/www/?category=Space">space_text</a></li></div>
Ideally this should work for an arbitrary number of matches including 1.print $1 . "; " . $2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching for one or more instances of text between tags
by choroba (Cardinal) on Oct 13, 2015 at 08:52 UTC | |
|
Re: searching for one or more instances of text between tags
by Skeeve (Parson) on Oct 13, 2015 at 08:14 UTC | |
|
Re: searching for one or more instances of text between tags
by AppleFritter (Vicar) on Oct 13, 2015 at 09:47 UTC | |
|
Re: searching for one or more instances of text between tags
by Jenda (Abbot) on Oct 13, 2015 at 14:28 UTC | |
|
Re: searching for one or more instances of text between tags
by tangent (Parson) on Oct 13, 2015 at 15:02 UTC |