Howdi,
This one got me thinking, you could just match on something as simple as
/ass/gi but as you say this would also flag up "harassment" etc, the
only way I can see of doing this is either have a big list, or only
allow words through that have a-z characters on both sides of the word.
So ... I wrote the following, and to test this I did have to include
some variations of nasty words, so I apologise for that now and would
just like to stress that swearing is not big || clever.
#!/usr/bin/perl
$sentance = 'you are a total harassment nastyfuckhead, and you fucking
need to fuck off and die you shitfaced twatshitface cunty nob!';
@words = $sentance =~ m/[A-Za-z]+/gi;
foreach(@words) {
# first check :: passes words that contain swear words as long as
# they have characters either side. ie (harassment).
# second check :: if the first check is passed then it checks again
# for swear words.
# third check :: if it gets through to here then its assumemed a
nice
# word.
if (m/[a-zA-Z].*(ass|fuck|cunt|shit)[a-zA-Z].*/gi) {
print "Good Word [boxed] : $&\n";
} elsif (m/ass|fuck|cunt|shit/gi) {
print "Bad Word [found] : $_\n";
} else {
print "Good Word [passed] : $_\n";
}
}
Sky Blueshoes wrote:
I've been trying to develop some regex's to match bad words. Just
comparing against a list of bad words doesn't work that well, because
I would have to include every possible use of a curseword, ie:
bullshit, shit, shithead, etc. Plus looping through every word in the
list would invariably be slow.
Here is an example of one such regex:
/(?:bull)shit/i
My problem here is getting the ending on there. I want this regex to
also match the words, shithead, shitter, etc, etc.
I know I could just have it match on the word shit, but this wouldn't
work for the word ass as it is located within words, such as
harassment or class. I'm not very good with the regex's and I was
wondering if some of you gurus could just help me cheat ;)
SkyBlueshoes
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>