相关疑难解决方法(0)

如何在Perl中从HTML中提取URL和链接文本?

我之前曾在Groovy中询问过如何做到这一点.但是,由于所有CPAN库,现在我在Perl中重写我的应用程序.

如果页面包含以下链接:

<a href="http://www.google.com">Google</a>

<a href="http://www.apple.com">Apple</a>

输出将是:

Google, http://www.google.com
Apple, http://www.apple.com

在Perl中执行此操作的最佳方法是什么?

html url perl parsing cpan

20
推荐指数
5
解决办法
3万
查看次数

如何在Perl中进行全局正则表达式匹配?

我试图在Perl中提出一个匹配多个模式的正则表达式,并像preg_match_allPHP 一样返回所有这些模式.

这就是我所拥有的:

$str = 'testdatastring';
if($str =~ /(test|data|string)/) {
        print "its found index location: $0 $-[0]-$+[0]\n";
        print "its found index location: $1 $-[1]-$+[1]\n";
        print "its found index location: $2 $-[2]-$+[2]\n";
        print "its found index location: $3 $-[3]-$+[3]\n";
}
Run Code Online (Sandbox Code Playgroud)

这只给了我第一场比赛,其中就是'测试'.我希望能够匹配所有出现的指定模式:'test','data'和'string'.

我知道在PHP中,你可以使用preg_match_all来达到这种目的:

if(preg_match_all('/(test|data|string)/', 'testdatastring', $m)) {
        echo var_export($m, true);
}
Run Code Online (Sandbox Code Playgroud)

上面的PHP代码将匹配所有3个字符串:'test','data'和'string'.

我想知道如何在Perl中执行此操作.任何帮助将不胜感激.

php regex perl preg-match-all

1
推荐指数
1
解决办法
8255
查看次数

标签 统计

perl ×2

cpan ×1

html ×1

parsing ×1

php ×1

preg-match-all ×1

regex ×1

url ×1