JSFiddle - React, Tailwind, and code Playground
HTML
<input id="search" type="text" value="bone on ^ * () a thing there and an hifi if the offer, of boffin."/>
JavaScript
$("#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");
}
});