我有以下多行字符串:
/*dummy comment */
/* comment about sum function jkhkdhfljkldjf
kjsdkjflskj
*/
int sum(int a,int b);
/*comment about mul function */
int mul(int a,int b);
如果使用以下正则表达式,则会得到两个输出匹配:
regex -> (?P<desc>(\/\*[\s\S]+?\*\/$))(?P<fun>\s*int\s*\b\w+\b\s*\(\w+\s+.+\s*(?:;$))
匹配#1:
desc:
/*dummy comment */
/* commect about sum function jkhkdhfljkldjf
kjsdkjflskj*/
fun:
int sum(int a,int b);
匹配#2:
desc:
/* comment about mul function */
fun:
int mul(int a,int b);
对于match#1,我得到两个注释,但我只需要最后一个注释,即,/*关于和函数jkhkdhfljkldjf kjsdkjflskj的注释*/我不想与/*伪注释*/匹配
请帮助我获得以下输出
匹配#1:
desc:
/* commect about sum function jkhkdhfljkldjf
kjsdkjflskj*/
fun:
int sum(int a,int b);
匹配#2:
desc:
/* comment about mul function */
fun:
int mul(int a,int b);
我无法调试您的regex,因为它在示例中的格式似乎不正确,所以这里有一个关于如何调试的工作片段。当注释解释正则表达式是如何工作的时,请仔细检查它们。你知道吗
我得到的结果是:
相关问题 更多 >
编程相关推荐