perl正则提取中文之间的数字
想要解析一个log,如下
========== 生成: 错误 5 个,告警 8 个 ==========
如何才能正确提取 5 和 8呢?
最近才研究正则,摸索半天,没搞出来,求高人指导!! perl?正则
[解决办法]
最近一直在做这个哈,给你说下,要用到解码加码方面的:
use Encode;
use Data::Dumper;
my $resultErr = undef;
my $resultWar = undef;
sub getString
{
my $file = "C:\\Users\\Desktop\";
$file = $file."log.txt";
open FH, $file or die "not find $file: $!";
my $a = undef;
my $i = 1;
while($a = <FH>) {
$a = decode("utf8", $a);
$a =~ /.*?(\d+).*?(\d).*/;
$resultErr->{"Error".$i} = $1;
$resultWar->{"Warning".$i} = $2;
$i ++;
}
print Dumper $resultErr;
print Dumper $resultWar;
close(FH);
}
getString();