I've got the following text:
#ifdef blah
a
#else
b
#endif
#ifdef blah
c
#endif
I'd like to create a perl regex that can be used to delete/replace the #ifdef blah / #endif and anything wrapped by them and to keep just whatever is under the #else if it exists. The above text after the action is performed should be:
b
I've tried something like this:
perl -i.bak -pe 'BEGIN{undef $/;} s/^#ifdef blah.*(^#else blah(.*))?#endif blah/\2/smg' test.c
However, their appears to be a problem marking the #else as occurring zero or more times and nothing gets selected.