Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to implement a scientific term extraction pattern in Perl however so far I am unsuccessful:
This is the pattern:((A|N)+|((A|N)*(NP)?)(A|N)*)N
It should return matches with sequences like: NNNN, NAAN, ANPN etc.
Partially it works. My Perl code looks like:However it shouldn't return a match with NNAPN since it should accept only NP sequence. How can I change it in order to work?my @can = ('NNAN', 'BPPAN','ANPN', 'NNAPN'); foreach $value (@can) { if ( $value =~ m/^((A|N)+|((A|N)*(NP)?)(A|N)*)N/ ) { print "match: + $value\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: matching patterns
by sovixi (Novice) on Jun 08, 2008 at 14:41 UTC | |
by throop (Chaplain) on Jun 08, 2008 at 22:38 UTC |