I am building a very basic profanity filter that I only want to apply on some fields on my application (fullName, userDescription) on the serverside
How about with fixed regexp:
check = new Regexp('(^|\b)'+badWords.join('|')+'($|\b)', 'gi');
check.test('ass') // true
check.test('suckass') // false
check.test('mass of whore') // true
check.test('massive') // false
check.test('slut is massive') // true
I'm using \b
match here to match for word boundry (and start or end of whole string).