We need to identify and then process switch/case statements in code based on some business rules.
A typical switch statement:
switch (a)
{
case "A":
case "B":
result = "T";
result1 = "F";
default:
result = "F";
}
I have been able to create two patterns to match the switch body in the first step and the case labels and body in the second step, however I am looking for a single regex which will allow me to extract case labels and bodies.
We do not have nested switches.
Kind regards,
Since switch statements can be nested traditional regexes can’t handle them (heck, even the fact that the
{}can be nested breaks them). Regexes can only parse Regular Languages. You need some form of parser to parse languages that are not regular. Depending on what language you have (it looks like C, but so do a lot of things), there may already be a parser you can use (such as Sparse for C).