开发者

How to find lines which are beginning from #, with exceptions

开发者 https://www.devze.com 2023-04-01 00:23 出处:网络
I\'ve C++ file, like: #include <stdio> #if 0 int a=1; #endif ..... 开发者_开发百科 How to write regular expression to find all lines which are beginning from #, except the lines which are star

I've C++ file, like:

#include <stdio>
#if 0
int a=1;
#endif
.....
开发者_开发百科

How to write regular expression to find all lines which are beginning from #, except the lines which are starting from the #include keyword?


Try this regex:

/^#(?!include).*$/gm


/^\s*#(?!include\b).*$/m

matches a line that starts with optional whitespace, then a #, unless followed by include.

So, in JavaScript:

result = subject.match(/^\s*#(?!include\b).*$/mg);
0

精彩评论

暂无评论...
验证码 换一张
取 消