Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^4: phrase match

by ambrus (Abbot)
on Dec 13, 2009 at 12:58 UTC ( #812583=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. 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";
    
  2. or download this
    kinase #inhibitor# #SET6# activates #p16(INK4A)# in cell-wall.
    
  3. or download this
    $sentence =~ s/(^| )($phrases_re)( |$)/$1#$2#$3/g for 0, 1;
    
  4. or download this
    use 5.010; given ($sentence) { s/ /  /g; s/(^| )($phrases_re)( |$)/$1#
    +$2#$3/g; s/  / /g; }
    
  5. or download this
    my %phrase; $phrase{$_}++ for @phrases;
    my @sentence = split /( +)/, $sentence;
    for (@sentence) { $phrase{$_} and $_ = "#" . $_ . "#"; };
    $sentence = join "", @sentence;
    
  6. or download this
    $sentence =~ s/(?<![^ ])($phrases_re)(?= |$)/#$1#/g;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://812583]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2021-06-12 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (53 votes). Check out past polls.

    Notices?