如何使用Perl在html中转换字符"%xx"

thi*_*khy 1 regex unicode perl uri

我打算从包含许多以"%xx"形式表示的unicode字符的网页中提取内容.当我使用Perl模块LWP获取网页时,使用Perl Regex自然处理这些unicode字符,如下所示.

my $html = "%20%26%40 ";
$html =~ s#%([0-9a-f]+)#\x{\1}#ig;
print "$html\n";
Run Code Online (Sandbox Code Playgroud)

但是上面的代码不起作用,它只输出"00".现在卡住......任何暗示都会受到赞赏.

谢谢,叶

Spu*_*ley 8

Perl已经在URI::Escape模块中内置了功能.你不需要乱用正则表达式

use URI::Escape;
my $encode = uri_unescape($string);
Run Code Online (Sandbox Code Playgroud)

请参阅此页面了解更多信息