Is there a way to search for multiple nested if statements in code using a regular expression?
For example, an expression that would locate an instance of if statements three or more layers deep with different styles (if, if/else, if/elseif/else):
if (...) {
<code>
if (...) {
<code>
if (...)
<code>
} else if (...) {
<code>
} else {
<code>
}
} else {
<code>
}
Using regexes to do source code searches is a bad idea. IMO. It is better to use some tool that parses the source code and then allows you to query the parse trees using (for example) XPath style path expressions.
The problem with regexes for source code searching is that they are generally too hard to read and write (unless you are a regex Guru), and they are prone to false positives and false negatives due to some edge case that the regex creator didn’t think of. (For example, using \uxxxx characters in keywords.)
Here are some tool links:
(Please feel free to suggest others.)