I am trying to develop a rather fast full text search. It will read the index, and should ideally run the matching in just one regex.
Therefore, I need a regex that matches lines only if certain words are contained.
E.g. for
my $txt="one two three four five\n".
"two three four\n".
"this is just a one two three test\n";
Only line one and three should be matched, since line two does not contain the word "one".
Now I could go through each line in a while() or use multiple regexes, but I need my solution to be fast.
The example from here: http://www.regular-expressions.info/completelines.html ("Finding Lines Containing or Not Containing Certain Words")
is what I need. However, I can't get it to work in Perl. I tried a lot, but it just doesn't come up with any result.
my $txt="one two three four five\ntwo three four\nthis is just a one two three test\n";
my @matches=($txt=~/^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$/gi);
print join("\n",@matches);
Gives no output.
In summary: I need a regex to match lines containing multiple words, and returning these whole lines.
Thanks in advance for your help! I tried so much, but just don't get it to work.