http://qs321.pair.com?node_id=601766

spivey3587 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all! I'm writing a vulgarity checker for my company that uses a dictionary of regex's to check for bad words. It works great except for one problem I'm having.

This is used for a message board that has a lot of sports related discussions. Some of you may be familiar with the South Carolina Gamecocks, and that's creating a problem in my engine for statements like "I'm a Game Cock fan". The engine basically does this:

study($input); foreach my $word (keys %$vulgar_list) { $regex = $vulgar_list->{$word}->{regex}; if ($input =~ m/$regex/) { $foundvulgar = $word; last; } }

Pardon the profanity here :) What I need is a check for /cocks?/ as long as it isn't preceeded by (a|the|game). Since perl doesn't have a "look behind", and there's no way to do !(a|the|game) within the regex, I'm stumped! I experimented with things like /(?!a|the|game)\s*cock/ but negative lookahead doesn't work that way.

I'm trying to figure out a way to do this in one or two regex's without having a special case in the code for this word (keeping in mind that I have to use a positive regex test with =~).

Any suggestions (even if it has to be multiple regex's) ??

Thanks guys. -Darin