JSFiddle - React, Tailwind, and code Playground
by osher
HTML
<textarea id="txt" style="width:100%">
The ass is on the bottom damn down where the shit comes out
</textarea>
<a href="JavaScript: $e('txt').value = clearProfanity($e('txt').value);">clear</a>
JavaScript
function $e(s){ return document.getElementById(s) }
var PROFANITY = ['ass','bottom','damn','shit']
, CENZOR = ("#####################").split("").join("########")
;
PROFANITY = new RegExp( PROFANITY.join("|") ,"gi");
function clearProfanity(s){
return s.replace( PROFANITY
, function(m) {
return CENZOR.substr(0, m.length - 1) + "!"
}
);
}
alert( clearProfanity("'ass','bottom','damn','shit'") );