Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: phrase match

by ambrus (Abbot)
on Dec 13, 2009 at 12:58 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://812583]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-24 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found