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

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.

Replies are listed 'Best First'.
Re^5: phrase marking
by kyle (Abbot) on Sep 10, 2008 at 19:31 UTC

    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.)