Raised This Month: $ Target: $400
 0% 

Replace blacklisted word unless it's a part of whitelisted word - string


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-08-2014 , 20:36   Re: Replace blacklisted word unless it's a part of whitelisted word - string
Reply With Quote #6

My last post is based on blacklist only.
You check the whole string for results using the last expression i posted.
It will match everything that contains "shit" with whitespace in between unless it has a prefix of "do".
Perhaps removing the first whitespace check would be good. Otherwise you might end up missing for example "You don't do shit".
The following will match "shit" and part of "shite", "dipshit" et.c. but not "doshit" (or "doshite").
Code:
(?<!do)s\s*h\s*i\s*t
If you want the whole word removed when matched with words that contains "shit" you'll have to expand the expression some more.
I'll show it without the whitespace checks so it will be easier to read.
The following will match the whole word of "shit", "shite", "dipshit" but not "doshit".
Code:
(?<!do)(?:dip)?shit(?:e)?
And with the full whitespace check...
Code:
(?<!do)s\s*h\s*i\s*t(?:\s*e)?
Making it further dynamic would probably only cause harm. In this case, not many words contains "shit". If you use the following expression for the purpose of matching everything starting with shit, like "shitface", "shithead" et.c., you would end up matching words like shitake.
Code:
(?<!do)s\s*h\s*i\s*t[\w]*
If you're doing whitelist the most simple solution would be to loop the whole whitelist, replacing the accepted words with placeholders, do the blacklist and then change the whitelisted words back. Hopefully the whitelist doesn't have to be so large, making it still pretty efficient.
__________________

Last edited by Black Rose; 03-08-2014 at 21:09.
Black Rose is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:05.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode