var str = ":test:smile:smile:test:smile:", reg = /(:\w+)(?=:\w+)+/g; str = str.replace(reg, "$1: "); alert(str);