开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜