开发者

Why doesn't my Perl match operator match anything?

开发者 https://www.devze.com 2022-12-09 19:57 出处:网络
I\'m new to Perl and playing around screen scraping and regex. I\'m trying to extract the \"title\" name of the following HTML block:

I'm new to Perl and playing around screen scraping and regex. I'm trying to extract the "title" name of the following HTML block:

... title="The Valley Downs Chicago"><img class="vimg120" ...

My simple Per开发者_如何学Cl code to do so is:

@htmlBlocks = split ("margin-bottom:20px",$content);
foreach $item (@htmlBlocks)
{
if (/\stitle="([^"]*)"/six)
{
    print $1;
}
}

but it doesn't print anything. while i'm troubleshooting it, i though i'd ask the experts if you see anything wrong or potentially problematic. thanks so much in advance for your help!


By default // search uses $_ variable. If you want to search another variable then specify it before =~. Here is example:

@htmlBlocks = split ("margin-bottom:20px",$content);
foreach $item (@htmlBlocks) {
    if ($item =~ /\stitle="([^"]*)"/six) {
        print $1;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消