in reply to Double regex match not working correctly.

The problem seems to be the location of your ()'s. To get the substitution to work correctly, use $string =~ s/([^<B>]($swapString)[^<\/B>])/<B>$1<\/B>/gi; Update:
if you don't want the period and spaces to be bold, use
$string =~ s/([^<B>])($swapString)([^<\/B>])/$1<B>$2<\/B>$3/gi;

Replies are listed 'Best First'.
Re: Re: Double regex match not working correctly.
by the_0ne (Pilgrim) on May 24, 2001 at 09:36 UTC
    Actually, the second one handled it exactly like I wanted. Thanks, I tried a variance of that but noticed I placed the parenthesis the wrong way that time also.

    However, the first one didn't seem to work how I thought it would, not sure I think I copied it exactly how you had it, but it didn't work correctly for me. It gave me this...

    string after first - bar there is a <B>foo bar</B> and a <B>bar foo</B> and also foo <B>foo</B>and bar

    ...but the second substitution you gave worked perfectly. Thanks for showing me the err of my ways.