Perl-正则表达式问题 [英] Perl -- regex issue
本文介绍了Perl-正则表达式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码来在字符串中获取子字符串,我正在使用正则表达式,但它们似乎无法正常工作.我该怎么办?
I have the following code to get a substring inside an string, I'm using regular expressions but they seem not to work properly. How can I do it?
我有这个字符串:
vlex.es/jurisdictions/ES/search?textolibre=transacciones+banco+de+bogota&translated_textolibre=,300,220,00:00:38,2,0.00%,38.67%,€0.00
我想得到这个子字符串:
and I want to get this substring:
transacciones+banco+de+bogota
代码:
open my $info, $myfile or die "Could not open $myfile: $!";
while (my $line = <$info>) {
if ($line =~ m/textolibre=/) {
my $line =~ m/textolibre=(.*?)&translated/g;
print $1;
}
last if $. == 3521239;
}
close $info;
错误:
Use of uninitialized value $line in pattern match (m//) at classifier.pl line 10, <$info> line 20007.
Use of uninitialized value $1 in print at classifier.pl line 11, <$info> line 20007.
推荐答案
$line
的第二个声明是错误的,请删除my
:
the second declaration of $line
is erroneous, drop my
:
$line =~ m/textolibre=(.*?)&translated/g;
这篇关于Perl-正则表达式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文