in reply to Re^2: Regex matching
in thread Regex matching
but I don't know how to tell the regex that I don't want every single sentence that start with a keyword and end with the other, but just sentences that have three or four words between the first and the second.
To get that result, you could change
while ($text =~ / $key (.*)? $value /g)
to
while ($text =~ /\s$key\s+((?:\S+\s+){0,3}\S+)\s+$value\s/g)
This captures 1 to 4 words. (Do you really want space before $key and after $value?)
A few questions more.
while (my $text=<$testo>){ for my $key (keys %hash){ my $value = $hash{$key}; while ($text =~ / $key (.*)? $value /g) { $arrayris[$indice]=$1; $indice++; } } }
If not, you would need to change the while loop, (testing the regular expression, not the file read),to an if statement.
Just a few questions.
Chris
|
|---|