我有一个包含文件中的文本:从相同的Perl正则表达式捕获多个匹配?
hello mayank1 kumar mayank21
yadav Kevin has at most
K
K minutes to perform this operations. He decides mayank3 that the string is super mayank4
if it is the lexicographically
smallest among all possible strings mayank15
that he can get. Your task is to help Kevin and
find this mayank2 lexicographically mayank8 smallest string mayank9
我怎样才能找到所有mayank<number>
?
我想:
use strict;
open(FH, "testfile.txt") or die "Can't open file for reading.";
while (my $line = <FH>) {
chomp($line);
while ($line =~ /(mayank.*?)/g) {
print "$1\n";
}
}
即给予:
mayank
mayank
mayank
mayank
mayank
mayank
mayank
mayank
使用:
while ($line =~ /(mayank.?)/g) {
print "$1\n";
}
我得到
mayank1
mayank2
mayank3
mayank4
mayank1
mayank2
mayank8
mayank9
请建议。
你是什么意思找到所有“mayank”?你期望你的程序产生什么输出? – redneb
对不起,不完整的,我寻找热塑成型为O/P为: mayank1 \ n mayank21 \ n mayank3 \ n mayank4 \ n mayank15 \ n mayank2 \ n mayank8 \ n mayank9 \ n – Mayank
我刚编辑该帖子(改进后的格式),并注意到所需的结果未被反引号包围,所以我们看不到'maya'中的''部分。 –
PerlDuck