我正在尝试在 Python 中转换字符串,例如:
string = 'void demofun(double* output, double db4nsfy[], double VdSGV[], int length)'
进入
wrapper = 'void demofun(ref double output, double[] db4nsfy, double[] VdSGV, int length)'
现在,在大多数情况下,我可以使用 , 的简单组合while来string.find()做到string.replace()这一点,因为我不需要干预变量名(例如outputor length),但我想不通的是替换这些字符串:
double db4nsfy[]-->double[] db4nsfy
double[] VdSGV-->double[] VdSGV
我该怎么做?我知道我会用 Python 中的一些 RTFM 正则表达式找到我的答案,但我希望从一个实际的例子开始。