In article <s7pdb9->,
"Ben Morrow " <> spake thusly:
>
> s/ (?:\s|<br>) \K \Q$original\E (?=\s|<br>) /$converted/ix;
In addition to Jan and Ben's excellent suggestions, please note that
the patterns don't need to be applied in a loop. You can do something
like this:
my $regex=join "|", map quotemeta, @profanityArr;
$text =~ s{ (?:\s|<br>) \K ($regex) (?=\s|<br>) }{"X" x length $1}ex;
The "|" lets you match alternatives in a single regex, while the /e
flag is used to eval an expression before performing a substitution.
As I'm sure you know, folks who want to bypass the filters can usually
figure out ways around them.
- Morty