I asked for help yesterday on this topic but I need to expand it and add something to the regex. Here's the FIDDLE of what I have so far to get rid of unwanted words in a string but now I need to also replace the non-word characters such as periods, commas, any slashes, stars, etc. How can I add the \W, if that's what I need to use for this? I tried many variations to no success. Please help out...
<input id="search" type="text" value="bone on ^ * ()
a thing there and an hifi if the offer, of boffin."/>
$("#search").bind('enterKey', function(e){
var search = $('#search')
.val()
.replace( /\b(on|a|the|of|in|if|an)\b/ig, '' )
.replace( /\s+/g, '-' );
alert( 'Replace spaces: ' + search);
});
$('#search').keyup(function(e){
if(e.keyCode == 13){
$(this).trigger("enterKey");
}
});