<script> var str = "2*x+((x+1)**2+(x+3)**2)/{x+1}-12" document.write(str + "<br>" + str.replace(/\((.*?)\)(?=\/)/, "{$1}") ) </script>