No offense, but you don't even have the basics. Your dept won't worry about the speed of Perl so much as your proficiency with it. You might want to start with Learning Perl. Then you might want to take a look at Mastering Regular Expressions, though you could save a few bucks and start with perlrequick and perlretut first.

To help you understand what's going on, let's reformat what you've got so we can see what we should search for:

my $line_in = <<EOT; <?xml-stylesheet href="perl1.css" type="text/css"?> <link href="//www.perl.org/css/perl1.css" rel="stylesheet"> <link href="/css/perl.css" rel="stylesheet"> EOT
You say you want to pull out the hrefs, but you use this pattern:
my @ss = $line_in =~ m{<(.*?)stylesheet(.*?)>}gis;
which says to find an angle bracket and save 0 or more chars as $1 (that's what the parens do) until you find "stylesheet". Skip "stylesheet" and then save 0 or more chars as $2 until you find a closing angle bracket. Ignore line breaks. Here is what you'll get:
$1 $2 |----| |--------------------------------| <?xml-stylesheet href="perl1.css" type="text/css"?> $1 $2 |--------------------------------------------| | <link href="//www.perl.org/css/perl1.css" rel="stylesheet"> $1 $2 |-----------------------------| | <link href="/css/perl.css" rel="stylesheet">
If you want to capture the hrefs, try matching them instead:
my @ss = $line_in =~ m/(href="[^"]+")/gi; print "$_\n" for @ss; # # href="perl1.css" # href="//www.perl.org/css/perl1.css" # href="/css/perl.css"
If you're looking for an href within a tag that contains the word stylesheet, where the word stylesheet may appear before or after the href...well, that's a little more complicated. Here it is, but you'll have to figure out how it works on your own.
my @ss = $line_in =~ m/<(?=[^>]*stylesheet).*(href="[^">]+")/gis;
--marmot

In reply to Re: Help with RegEx by furry_marmot
in thread Help with RegEx by mr_p

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.