var selectWithDescription = function(text){ var newText = text; //array of find replaces var findreps = [ {find:/^([^\-]+) \| /g, rep: '$1'}, {find:/([^\|><]+)$/g, rep: '$1'} ]; for(var i in findreps){ newText = newText.replace(findreps[i].find, findreps[i].rep); } return newText; } // vim:syntax=javascript