I don't think a single regular expression is the best way to solve this problem, since it either matches, or it doesn't. You can't print/log/whatever any information as of why there is no result. The shortest solution I would want to use still uses three regexen:

if ($html =~ m#<noframes>(.+?)</noframes>#is) { @urls = grep { $_ !~ m#microsoft\.com|netscape\.com# } $& =~ m#<a +href="([^"]+)"#gi; }

However, there are still issues with this: It assumes, that "href" directly follows "<a", which, by no means is neccessary. So a little longer, but better readable and more clear solution is the following:

if ($html =~ m#<noframes>(.+?)</noframes>#is) { $noframes = $1; } else { die "Couldn't find noframes tags"; } while ($noframes =~ m#<a[^>]+>#gis) { my $link = $&; my ($url) = $link =~ m#href\s*=\s*"([^"]+)"#i; if ($url and $url !~ m#microsoft\.com|netscape\.com#i) { push (@urls, $url); } }

I didn't come up with a regex-only solution, mainly to the lack of time, but the only reason I would write a solution for this problem entirely as regex was to develop regex-skills ;) Hope this helps :)

Regards,
-octo


In reply to Re: Question Regarding Regular Expressions and Negated Character Classes by flocto
in thread Question Regarding Regular Expressions and Negated Character Classes by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.