String.prototype.trim = function(charList) { return this.replace(/^\s+|\s+$/g, ''); }; var str = 'jdhf ,,, dshfjk,,,,sah~!@#$%^dksa d<><><>gfhgdf sd'; var result = str.replace(/[^\-\wа-я]+/gi, ' ').trim().split(' '); alert(result.join('\r\n'));