gpt4 book ai didi

Javascript : find regexp with capture to replace a^b by Math. pow(a, b)

转载 作者:行者123 更新时间:2023-11-30 12:11:58 26 4
gpt4 key购买 nike

我的字符串如下:

str = "(2+2)^(4*(5+6^(5^6))))";

如您所见,幂可以嵌套在另一个幂中,带或不带括号。

所以我想通过使用正则表达式来转换这个字符串,用 javascript 的 Math.pow(a,b) 替换 ^。

一个想法?在此先衷心感谢您。

最佳答案

我认为使用正则表达式来解析表达式对你来说不是很好......

为什么不使用像 http://mathjs.org/ 这样的数学表达式解析器库呢?

关于Javascript : find regexp with capture to replace a^b by Math. pow(a, b),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33502961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com