Regex 以任意顺序匹配多个模式(Perl)

Regex 以任意顺序匹配多个模式(Perl),regex,perl,Regex,Perl,我有一个文件看起来像(但大得多): 我想查找在“PROKKA_uuxxxxx”之前包含所有这些内容的行: 下面的脚本将找到它们,但似乎只是按照它们在脚本中的写入顺序(例如,当我知道事实上有三个都在的行时,只返回一个包含196 |,120 |,630 |的行,但顺序不同): #/usr/bin/perl-w使用strict;使用警告; #从groups.txt获取所有组中存在的基因 #扫描orthomcl的输出,以获得仅核心开放的基因(在“中,我建议使用前瞻: ^ (?=.*120\|PROKKA

我有一个文件看起来像(但大得多):

我想查找在“PROKKA_uuxxxxx”之前包含所有这些内容的行:

下面的脚本将找到它们,但似乎只是按照它们在脚本中的写入顺序(例如,当我知道事实上有三个都在的行时,只返回一个包含196 |,120 |,630 |的行,但顺序不同):

#/usr/bin/perl-w使用strict;使用警告;
#从groups.txt获取所有组中存在的基因

#扫描orthomcl的输出,以获得仅核心开放的基因(在“中,我建议使用前瞻:

^
(?=.*120\|PROKKA_\d+)
(?=.*196\|PROKKA_\d+)
(?=.*630\|PROKKA_\d+)
.*


(为了可读性,这被分为多行)。从每行的开头开始,查看所有3个条件:120、196和630。如果找到它们,则
*
将与该行匹配。

您粘贴在那里的代码有答案,甚至在注释中解释了答案,只是有问题

您粘贴的内容:

while (my $line = <IN>) {
#change the VS1 to match your unique phage ID add "& ($line =~m/VS11\|/)" to add more rules to match . will need 15 for 15 phage if ($line =~ m/196\|/gi && $line =~ m/120\|/gi && $line =~
m/630\|/gi)#(=~m/120\|/gi))#($line =~m/196\|/gi)

这可能会更具可读性,但我们需要完整的脚本。

那么您需要的最终输出是什么?我对此不是很清楚,抱歉。我只需要包含所有三个(120 |,630 |,196 |)的行任意次数。有些行只有1或2个,需要删除。这完全符合我的预期,并且与我通过更改每次运行的脚本顺序而创建的测试文件相匹配。非常感谢!我以前从未听说过“展望”。。。
#!/usr/bin/perl -w use strict; use warnings;

#get genes that are present in all groups  from a groups.txt

#scans through output of orthomcl to get genes that are only core open (IN,"<$ARGV[0]")  or die $!;

while (my $line = <IN>) {
#change the VS1 to match your unique phage ID add "& ($line =~m/VS11\|/)" to add more rules to match . will need 15 for 15 phage if ($line =~ m/196\|/gi && $line =~ m/120\|/gi && $line =~
m/630\|/gi)#(=~m/120\|/gi))#($line =~m/196\|/gi)

#if (/(?=.*re1)(?=.*re2)(?=.*re3)/s)

#& ($line =~m/630\|/) & ($line =~m/120\|/)   #& ($line =~m/IME1\|/) #&
#($line =~m/KBNP\|/) & ($line =~m/LUZ7\|/) & ($line =~m/PA26\|/) & ($line =~m/RLP1\|/) & ($line =~m/VC01\|/) &
#($line =~m/DSS3\|/)  & ($line =~m/EcP1\|/)  & ($line =~m/G7C\|/) & ($line =~m/JA1\|/) & ($line =~m/LIT1\|/) &
#($line =~m/N4\|/) & ($line =~m/pS6\|/) & ($line =~m/RPP1\|/) & ($line =~m/VBP3\|/) & ($line =~m/VBP4\|/) &
#($line =~m/058\|/)  &  ($line =~m/076\|/)  &  ($line =~m/JWA\|/)  &  ($line =~m/JWD\|/) & ($line =~m/PRES\|/)    { print $line ; } }
^
(?=.*120\|PROKKA_\d+)
(?=.*196\|PROKKA_\d+)
(?=.*630\|PROKKA_\d+)
.*
while (my $line = <IN>) {
#change the VS1 to match your unique phage ID add "& ($line =~m/VS11\|/)" to add more rules to match . will need 15 for 15 phage if ($line =~ m/196\|/gi && $line =~ m/120\|/gi && $line =~
m/630\|/gi)#(=~m/120\|/gi))#($line =~m/196\|/gi)
while (my $line = <IN>) {
# change the numbers, which are phage IDs;
# e.g., to match your unique phage ID, say 196, add:
#   && ($line =~ m/196\|/)
#
  if ($line =~ m/196\|/gi && $line =~ m/120\|/gi && $line =~ m/630\|/gi)) {
  }
}