in reply to Double regex match not working correctly.
Square brackets are for defining a list of characters to match any one of (or not with a ^) in a single character position. The [^<B>] and [^<\/B>] will match any character which is not inside of the square brackets. Not the string <B> or </B> as I believe you were trying to not match.$string =~ s/[^<B>]($swapString)[^<\/B>]/<B>$1<\/B>/gi;
I expect I could explain this more clearly if it wasn't first thing in the morning! Basically with your $string the regex above would be as well written...
and if you want to not match something that's more than one character then try...$string =~ s/[^>]($swapString)[^<]/<B>$1<\/B>/gi;
larryk#!/usr/bin/perl -w use strict; $_ = "<b>foo</b> foo <b>bar</b> bar <b>foo</b> foo <b>bar</b> bar\n"; print; s/(?!<b>)(foo|bar)(?!<\/b>)/XXX/gi; print;
|
|---|