I want to replace some
math functions with
Math.sin. This is what I've tried. I expect the results to be that
Math.cos would be replaced by
re=/[Math\.cos|Math\.tan]/g; s="Math.cos(0)+Math.cos(0)"; s=s.replace(re,"Math.sin"); alert(s);
The result I would expect would be
Math.sin(0)+Math.sin(0) instead it is
I'm not sure what to try to fix the code.
The square brackets radically change the meaning of your regular expression. Get rid of them.
re = /Math\.cos|Math\.tan/g;