小编Shm*_*ser的帖子

提取包含在 C 文件中

我需要在 C 文件中提取所有包含的库,但我遇到了一些问题。我对此的解决方案是这样的:

grep -oP '#(?:\/\*\w*\*\/|)include(?:\/\*\w*\*\/|\s*)"\w*.h"|<\w*.h>' main.c
Run Code Online (Sandbox Code Playgroud)

例如,此正则表达式在注释中采用库

/*#include <stdlib.h>*/
Run Code Online (Sandbox Code Playgroud)

而且我不知道如何让该脚本只给我没有#include 的库名称

如何修复我的正则表达式使其正常工作?

更新:

主文件

#include  "string.h"
#include <stdlib.h>
 #include "math.h"
    #include "stdint.h"
#/*comment*/include /*comment*/ <fenv.h>  
//#include <iostream>
#/**/include "something.h"
/* comment */#include "float.h"
/*#include "library.h"*/
int main() {

}
Run Code Online (Sandbox Code Playgroud)

我想要的是:

"string.h"
<stdlib.h>
"math.h"
"stdint.h"
<fenv.h>
"something.h"
"float.h"
Run Code Online (Sandbox Code Playgroud)

grep c perl

1
推荐指数
1
解决办法
513
查看次数

标签 统计

c ×1

grep ×1

perl ×1