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);
精彩评论