ziargon,
<script>
function balance(a) {
for (var d = /(\u005B|\u0028|\u007B)[^\u005B\u0028\u007B]*?$/,
e = {
"(": /\u0028[^\u007D\u005D]*?\u0029/,
"[": /\u005B[^\u0029\u007D]*?\u005D/,
"{": /\u007B[^\u0029\u005D]*?\u007D/
}, b, c = !0; c;) b = a, a = a.replace(d, function (a, b) {
return a.replace(e[b], "")
}), b == a && (c = !1);
return !/[\u005B\u005D\u0028\u0029\u007B\u007D]/.test(a)
};
function foo(a) {
for (var c = /\((.*?)\)(?=\/)/g, e = /\((.*?)\)(?=\/)/, d, b = 0; d = c.exec(a); b++)
balance(d[0]) && (b--, a = a.slice(0, b) + a.slice(b).replace(e, "{$1}")), c.lastIndex = b;
return a
};
var str = "(-(-(4*x**2+12))/(x**3+6*x)) int(-(-(4*x**2+12))/(x**3+6*x))=5+((2*log(x))/(log(x**2+6)))"
document.write(str + "<br>" + foo(str))
</script>