I want to find the #else case for certain a C preprocessor define.
Example:
#if defined(my_define)
// multiple
// lines
// of
// code
#else
// multiple
// lines
// of
// code
#endif
Or
#if defined (my_define)
// same as above from here
But I do not want to match a case without #else:
#if defined(my_define)
// multiple
// lines
// of
// code
#endif
I don't care for nested #ifs, just the cases above.
I tried starting with
defined..?my_define.(\r\n|\r|\n)?
I don't know how to handle the arbitrary number of lines in between the directives.
#if defined..?my_define\b(?:(?!#(?:end)?if)[\s\S])*#else(?:(?!#(?:end)?if)[\s\S])*#endifto include the defines name (and whitespace) and it works flawless :-) Feel free to write an answer, so I can mark it as solved.