I followed your suggestion and tried this:
use strict;
use Regexp::Common;
(my $reg = $RE{profanity}) =~ s{\A \Q(?:\b\E (.*) \Q\b)\E \z}{$1}xms;
while ( my $word = <DATA> ) {
chomp $word;
if ( $word =~ m/$reg/ ) {
print "Profanity detected: \"$word\"\n";
} else {
print "$word\n";
}
}
__DATA__
aaaabbbbcccc
aaaashitcccc
aaaa1234cccc
ddddeeeeffff
This way it will find embedded "bad words" without the need for spaces around them, which is what I wanted. I realize the logic in requiring the word boundaries. But I think the fact that $RE{num}{int} finds embedded numbers made me assume that $RE{profanity} should work the same way, or else there might be a switch to toggle the behavior one way or the other.
The reason I need this is to generate temporary (one-use) passwords (like when someone requests a password reset on a website). The generated password should, ideally, be a jumble of random letters and/or numbers, but I don't want to accidentally send someone a password with an "obvious" obscenity embedded, so a simple filter like this is helpful.
Thanks!