- or download this
use warnings;
$sentence='kinase inhibitor SET6 activates p16(INK4A) in cell-wall.';
...
my $phrases_re = join '|', map { quotemeta } @phrases;
$sentence =~ s/(^| )($phrases_re)(?= |$)/$1#$2#/g;
print $sentence, "\n";
- or download this
kinase #inhibitor# #SET6# activates #p16(INK4A)# in cell-wall.
- or download this
$sentence =~ s/(^| )($phrases_re)( |$)/$1#$2#$3/g for 0, 1;
- or download this
use 5.010; given ($sentence) { s/ / /g; s/(^| )($phrases_re)( |$)/$1#
+$2#$3/g; s/ / /g; }
- or download this
my %phrase; $phrase{$_}++ for @phrases;
my @sentence = split /( +)/, $sentence;
for (@sentence) { $phrase{$_} and $_ = "#" . $_ . "#"; };
$sentence = join "", @sentence;
- or download this
$sentence =~ s/(?<![^ ])($phrases_re)(?= |$)/#$1#/g;