I REALLY would not advise doing this because he could create some strange situations, such as filtering things that in the context would be completely beautiful, like "this male dog."
Having said that you can do something like ... It should work, it is not ideal, but it will work.
var filter = ['sex','s/e/x']; // and so on for each bad word. $(document).text(function(i,txt { for (var i = 0; i < filter.length; i++) { var pattern = new RegExp(filter[i], 'gi'); var clean = '*'.repeat(filter[i].length); txt = txt.replace(pattern, clean); } return txt; });
Hope this helps!
edit took me so long to write this section of code, I did not see another answer there. Go with this imo, it looks much nicer and more versatile.
source share