in reply to Re^2: phrase marking
in thread phrase marking

Yes, I think that's right. If you have overlapping phrases to mark, you'd have to figure out how to you want to deal with those, and then you'd probably have to use a different solution. If you have some phrases that are preferred over others, you can order them before building the expression.

Replies are listed 'Best First'.
Re^4: phrase marking
by newbio (Beadle) on Sep 10, 2008 at 18:51 UTC
    Hi Kyle, one more question. How can I adapt your solution for full word matching (i.e. with spaces as boundaries), although the solution works very well for partial matching? Nice thing about the solution is that I could have a matching preference order between single words and phrases by sorting them according to their length in the 'phrases' array. Thanks a lot.

      Include word boundaries in the patterns.

      my @phrases = ( 'pail of water', 'pale horse' ); my $phrases_re = join '|', map { "\\b$_\\b" } map { quotemeta } @phrases; foreach my $sentence ( @sentence_source ) { $sentence =~ s/($phrases_re)/\#$1\#/g; }

      (Note the extra map.)