function toCamel(str) { str = str.replace(/(\w)/, (match, $1) => `${$1.toUpperCase()}`) while(str.match(/\w_\w/)) { str = str.replace(/(\w)(_)(\w)/, (match, $1, $2, $3) => `${$1}${$3.toUpperCase()}`) } return str } console.log(toCamel('a_c_d_ef_g')) // ACDef