A very lazy oneliner: function dashesToParentheses(str) { return str.replace(/-/g, "(") + str.replace(/[^-]*-[^-]*/g, ")"); } There's nothing to say... but I was asked to. The first term is obvioius: Just replace all dashes by opening parentheses. The second replaces all dashes by closing parentheses while dropping everything else.