in reply to Pattern Matching Q?

So you want to match:
m{ <strong # match "<strong" .*? # skip to the next ( # (start capturing) http:// # "http://" .*? # skip to the next ) # (stop capturing) & # ampersand }x
Or, more concisely, m{<strong.*?(http://.*?)&}.

Replies are listed 'Best First'.
Re^2: Pattern Matching Q?
by 80degreez (Initiate) on Nov 27, 2007 at 18:42 UTC
    With that code that you pasted to me, where would the resulting match be stored?
      All pattern matches are stored in $1, $2, $3 depending on the set of parens that matched. In this case it will be stored in $1.

      Another way of looking at this is (to borrow from educated_foo's answer: ($url = $1) if (m{<strong.*?(http://.*?)&});

        I tried with the following code:
        use strict; use WWW::Mechanize; use HTTP::Cookies; use HTML::TokeParser::Simple; my $mech = WWW::Mechanize->new( stack_depth => 1, agent =>"Mozilla/5.0 + (X11; U; Linux i68+6; en-US; rv:1.7) Gecko/20040918 Firefox/0.9.3 ") +; my $pic = "C:\/LV3.JPG"; $mech->cookie_jar( HTTP::Cookies->new(stack_depth => 1) ); $mech->get("http://tinypic.com"); if($mech->content() =~ /UPLOAD NOW/ ){ print "TinyPic loaded... "; $mech->form_name("upload_form"); $mech->field('the_file' => $pic); $mech->submit(); m{ <strong # match "<strong" .*? # skip to the next ( # (start capturing) http:// # "http://" .*? # skip to the next ) # (stop capturing) & # ampersand }x print $1; }
        and it returned a syntax error. I also tried with the other version you gave me here:
        use strict; use WWW::Mechanize; use HTTP::Cookies; use HTML::TokeParser::Simple; my $mech = WWW::Mechanize->new( stack_depth => 1, agent =>"Mozilla/5.0 + (X11; U; Linux i68+6; en-US; rv:1.7) Gecko/20040918 Firefox/0.9.3 ") +; my $pic = "C:\/LV3.JPG"; $mech->cookie_jar( HTTP::Cookies->new(stack_depth => 1) ); $mech->get("http://tinypic.com"); if($mech->content() =~ /UPLOAD NOW/ ){ print "TinyPic loaded... "; $mech->form_name("upload_form"); $mech->field('the_file' => $pic); $mech->submit(); m{<strong.*?(http://.*?)&}; print $1; }
        This version didn't get a syntax error but also didn't output anything