Thank you all Monks for your comments.
Here is my reworked solution, it seems to work on my sample sentences, but I am not really sure if it will work in all types of situations. If you see any glitch with this solution, please let me know.
Thanks once again.
my @phrases = ( 'kinase i', 'hib', 'tor', 'tor SET6', 'SET6', 'p16(INK +4A)', 'cell', 'MAP', 'H1 inhibitor' ); my $sentence='kinase inhibitor SET6 MAP H1 inhibitor activates p16(INK +4A) in cell-wall'; for (my $i=0;$i<=$#phrases;$i++) { $phrases[$i]=~s/\s+/ /g; } my $phrases_re = join '|', map { quotemeta } @phrases; $sentence=~s/\s+/ /g; $sentence=' '.$sentence.' '; $sentence =~ s/\s($phrases_re)\s/ \#$1\# /g; $sentence=~s/\s+/ /g; $se +ntence =~ s/^\s+|\s+$//g; print "$sentence\n"; #Output: 'kinase inhibitor #SET6# #MAP# #H1 inhibitor# activates #p16( +INK4A)# in cell-wall'
In reply to Re: phrase match
by newbio
in thread phrase match
by newbio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |