Since your data set is fairly small, you might want to consider building the regex out of the pieces you're looking for:
#!/usr/bin/perl -w use strict; our ($Gene, $Target, $Input) = qw/gene.txt target.txt input.txt/; open Gene or die "$Gene: $!\n"; open Target or die "$Target: $!\n"; open Input or die "$Input: $!\n"; my $gene = join "|", grep {chomp} <Gene>; my $target = join "|", grep {chomp} <Target>; chomp(my $input = <Input>); close $_ for qw/Gene Target Input/; my $verbs = 'localizes to|held|located in|localization|translocated to +|targets|reaches|exported|export'; # Note corrected 'split' regex for my $sentence (split /\. [A-Z]/, $input){ my $found; for ($sentence =~ /($gene).*?($verbs).*?($target)/ig){ print "$_\t"; $found++; } print "\n" if $found; }
Output:
PfAMA1 located in micronemes PfROM1 located in Golgi AMA1 held micronemes AMA1 held micronemes
In reply to Re: Simple RegEX text parser
by oko1
in thread Simple RegEX text parser
by I-Box
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |