grasshopper!!! has asked for the wisdom of the Perl Monks concerning the following question:
I having trouble parsing links out of a web page source. The regexp picks up the beginning of one similar match and the second part of a similar match.I have used lookback's and lookforward's to no avail.The false match is the first match the rest are correct. Thanks in advance.
use strict; use warnings; use WWW::Curl::Easy; my $curl = WWW::Curl::Easy->new; $curl->setopt(CURLOPT_HEADER,1); $curl->setopt(CURLOPT_URL, 'http://www.reddit.com/r/wallpapers.rss'); my $response_body; $curl->setopt(CURLOPT_WRITEDATA,\$response_body); # Starts the actual request my $retcode = $curl->perform; # Looking at the results... if ($retcode == 0){ print("Transfer went ok\n\n"); my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE); # judge result and next action based on $response_code open(F ,">/home/philip/Desktop/reg-out.txt"); print F "$response_body\n\n"; close(F); my @urls=$response_body =~ m{(http://b.thumbs.redditmedia.com/(?!png) +(?<!png).+?(?!png)(?<!png)\.jpg)}gi; #print("Received response: $response_body\n\n"); print scalar @urls ."\n\n"; $" ="\n\n"; print "@urls\n"; #`feh --bg-seamless $urls[$number]`; } else { # Error code, type of error, error message print("An error happened: $retcode ".$curl->strerror($retcode)." ".$ +curl->errbuf."\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex problem
by AnomalousMonk (Archbishop) on Nov 03, 2015 at 22:16 UTC | |
by grasshopper!!! (Beadle) on Nov 04, 2015 at 21:28 UTC | |
by grasshopper!!! (Beadle) on Nov 05, 2015 at 00:18 UTC | |
by AnomalousMonk (Archbishop) on Nov 05, 2015 at 00:48 UTC | |
|
Re: regex problem
by stevieb (Canon) on Nov 03, 2015 at 21:14 UTC | |
|
Re: regex problem
by ExReg (Priest) on Nov 03, 2015 at 22:30 UTC | |
by ExReg (Priest) on Nov 03, 2015 at 23:36 UTC |