我正在尝试寻找一个正则表达式来匹配C++头文件中不是虚拟的方法声明。我让它在大多数情况下都能工作,但是如果在virtual之后有一个换行符,并且方法声明在下一行,那么我的正则表达式将匹配它,这不是我想要的。因此,我需要正则表达式引擎回溯到前一行并检查virtual关键字。下面是一个基本的例子:
源文件片段:
void Process(char* name, int val); // Should match, this one works
virtual char* GetName(); // Should not match since it is virtual, this one works
virtual
flag_type SetValue(uint8 resourceIndex, char* name); // Should not match, but this line matches since virtual is on previous line!下面是我的正则表达式:(^\s*\w+\**(?<!virtual)\s+\w+\s*\()(\s*\w+\**\s+\**\w+,?)*\s*\)\s*;
发布于 2012-05-01 05:46:51
我发现了一些适合我的东西,包括Emanuele指出的缺陷(尽管它也会在注释行中匹配):\b(?<!virtual\s+)\w+\**\s+\w+\s*\((\s*\w+\**\s+\**\w+,?)*\s*\)\s*;
https://stackoverflow.com/questions/10354986
复制相似问题