Working Demo http://jsfiddle.net/cse_tushar/U94Le/
$('#b').click(function () {
tags = $('#message').val();
tags = tags.replace(/!/g, '');
var excludeWords = ['took', 'the', 'a', 'to', 'with', 'dog', 'this'];
$.each(excludeWords, function (i, v) {
pos = tags.indexOf(excludeWords[i]);
while (pos > -1) {
tags = tags.replace(" " + excludeWords[i] + " ", ' ');
pos = tags.indexOf(excludeWords[i], pos + 1);
}
});
console.log(tags);
tags = tags.split(' ');
console.log(tags);
$('#output').html('<pre>' + tags + '</pre>');
});