I know there are many arguments as to why this is a bad idea, but in my implementation I\'m planning on enabling/disabling bad words in the account settings. In other words
Something like this might work:
String.prototype.repeat = function(num){
return new Array(num + 1).join(this);
}
var filter = ['ass', 'piss'];
$('.post').text(function(i, txt){
// iterate over all words
for(var i=0; i
Working example on jsFiddle
Edit: Added boundaries so it won't replace words that contain the swear words. I've used double backslashes because backslashes should be escaped in a string, see this topic.