Help for this page

Select Code to Download


  1. or download this
    $string =~ s/[^<B>]($swapString)[^<\/B>]/<B>$1<\/B>/gi;
    
  2. or download this
    [^<B>]  <- this matches any *single* char that is not a < B  >
    ($swapString) <- this put the match for $swapstring into $1
    [^<\/B>]  <- this matches any *single* char that is not a < / B  >
    
  3. or download this
    $string =~ s/([^<B>]($swapString)[^<\/B>])/<B>$1<\/B>/gi;
    
    there is a <B>foo bar</B> and a <B>bar foo</B> and also<B> foo </B>and
    +<B> bar.</B>
    
  4. or download this
    $string =~ s/(?<!<B>)($swapString)(?!<\/B>)/<B>$1<\/B>/gi;
    
    # this gives:
    
    there is a <B>foo bar</B> and a <B>bar foo</B> and also <B>foo</B> and
    + <B>bar</B>.