Don*_*ong 2 regex perl utf-8 arabic
我正在解析一些html页面,需要检测里面的任何阿拉伯字符.试过各种正则表达式,但没有运气..
有谁知道这样做的工作方式?
谢谢
这是我正在处理的页面:http: //pastie.org/2509936
我的代码是:
#!/usr/bin/perl
use LWP::UserAgent;
@MyAgent::ISA = qw(LWP::UserAgent);
# set inheritance
$ua = LWP::UserAgent->new;
$q = 'pastie.org/2509936';;
$request = HTTP::Request->new('GET', $q);
$response = $ua->request($request);
if ($response->is_success) {
if ($response->content=~/[\p{Script=Arabic}]/g) {
print "found arabic";
} else {
print "not found";
}
}
Run Code Online (Sandbox Code Playgroud)
Chr*_*is 5
如果您使用的是Perl,则应该能够使用Unicode脚本匹配运算符. /\p{Arabic}/
如果这不起作用,你将不得不查找阿拉伯语的Unicode字符范围,并测试它们是这样的/[\x{0600}\x{0601}...\x{06FF}]/.