str="ui-button ui-state-default ui-state-hover ui-state-hover ui-corner-all ui-state-hover"; myclass='ui-state-hover'; reg= new RegExp('(^|\\s+)' + myclass + '(?=\\s+|$)', 'gi'); str= str.replace(reg,''); alert(str);