var str = 'aa bb cc | ххx фвыывфывф'; var out =str.replace(/^.*?(?: \| )(\S+?\S(?=\s|$))\s*.*$/ig,'$1') alert('>'+out+'<')