Here's an interesting one. Anyone have a good RegEx for converting all (first) ^ (second) to Math.pow((first), (second))?
EDIT:
The best I have so far is
s = s.replace(/((?:d+.?d*)|w+|((?:(?:[^()]*(?:([^()]*)))*)))s*^s*((?:d+.?d*)|w+|((?:(?:[^()]*(?:([^()]*)))*)))/g, 'Math.pow($1, $2)') // replace expression ^ expression with Math.pow($1, $2)
The answers so far are not general enough. They don't cover something like (var1 + var2)^2 let alone (var1 * (var2 + var3))^2
The solution will have to work with parentheses.
You can use strfriend.com to help visualize the regex as you make it. That's what I've been doing.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…