Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有很多带有电源符号的符号表达式,我想在 C++ 程序中复制它们。但是,它们具有^C 中未使用的电源符号。对于快速进行更改有什么建议吗?^我应该使用 i can make gcc to see as的正则表达式pow()吗?
^
pow()
为了确保不会弄乱任何东西,您需要一个解析器,它知道 a 何时^实际用作电源符号(而不是例如在注释中,字符串)。
但是您可能会使用一个简单的正则表达式:
替换(\w+)\s*\^\s*(\w+)为pow(\1,\2)。
(\w+)\s*\^\s*(\w+)
pow(\1,\2)
这应该涵盖大多数情况并且相当安全。
当然,如果有更多的参数,它会失败,比如 in等。这个正则表达式只匹配or之类的(a + b) ^ (c + d)东西。它也没有正确匹配,所以如果可能发生这些,你需要a^b2^3x^0.5([\w.]+)\s*\^\s*([\w.]+)
(a + b) ^ (c + d)
a^b
2^3
x^0.5
([\w.]+)\s*\^\s*([\w.]+)