Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Regex solution needed

by hangon (Deacon)
on Feb 24, 2007 at 10:32 UTC ( [id://601864]=note: print w/replies, xml ) Need Help??


in reply to Regex solution needed

Darin, something about your problem kept nagging me. Have you considered also keeping an *exceptions* dictionary? This would allow flexibility in adjusting for future problem words without modifying your code. It would also let you handle phrases, and uses two trivial regex's. Something similar to the following:

# exceptions dictionary our @Exceptions = ( 'game cocks', 'gamecocks', #etc ); # censor dictionary our @Vulgarities = ( 'cocks', 'cock', #etc ); $censored = censor($post); sub censor{ # get a copy of the post my $copy = shift; # remove all exceptions for $except (@exceptions){ $copy =~ s/$except//gi; } # now check for banned words or phrases for $vulgar (@vulgarities){ if ($copy =~ /$vulgar/i){ return 1; } } return; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://601864]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-19 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found