I am trying to write a regex using perl but I need some help.
What I want to do is the following, suppose that I have these texts as examples:
1- [NP some/NN text/NNP here/NNP]
I am interested in the words labelled by /NNP, so I want my regex to search every line until it finds:
[NP then a space then (may or may not find) a word labeled with /NN then one or more words labelled with /NNP (and would contain some special characters).
I want to extract the words labelled with /NNP from each line so the result would be:
1- text here
what I have done so far is to extract the labelled words with /NNP from all the examples
while ($line =~ m/\s(\S*?)\/NNP/gs)
{
my $word = $1;
print $word." ";
}
print "\n";
Any Ideas pleas?
Perhaps:
And then you asked to be able to skip lines with only one labeled word. For that, I might do: