且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Perl中的纯文本中提取URL?

更新时间:2023-02-19 09:51:17

也许您想要 URI ::查找,可以在任意文本中查找URI.您提供的代码参考中的返回值将生成URL的替换字符串,因此,如果您只想摆脱URI,则可以只返回空字符串:

Perhaps you want URI::Find, which can find URIs in arbitrary text. The return value from the code reference you give it produces the replacement string for the URL, so you can just return the empty string if you merely want to get rid of the URIs:

use URI::Find;

my $string = do { local $/; <DATA> };

my $finder = URI::Find->new( sub { '' } );
$finder->find(\$string );

print $string;

__END__
This has a mailto:joe@example.com
Go to http://www.google.com
Pay at https://paypal.com
From ftp://ftp.cpan.org download a file