-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathIfDef.regex.txt
More file actions
16 lines (15 loc) · 761 Bytes
/
IfDef.regex.txt
File metadata and controls
16 lines (15 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Matches C/C++ #if/#ifdef/#ifndef .. #endif
(?m)(?<!//)\#\s{0,}(?=if) # As long as we're not after comments, Match the , followed by
(?<If>if[^\s]+) # Match <If> (and the rest of the word)
(?<Condition>.+?$) # the <Condition> is anything until the end of the line
# Now things get tricky. Because ifdefs can nest, we need a balancing group
(?>
[^\#]+ # Any non-preprocessor character matches, and doesn't change the balance
|
(?<!//)\#if.+?$(?<Depth>) # An if Increases the <Depth>
|
(?<!//)\#endif(?<-Depth>) # An EndIf Decreases the Depth
|
\# # Match any remaining
)*(?(Depth)(?!)) # Match Until EndIf is balanced
(?<!//)\#endif # Match the endIf