I have some issue with C++ regex, and hope someone could offer some help. :)
Currently, base on the "rxAssign" as shown below, I am able to detect math expression that look like:
- x = x;
- x = a + 3 * 90 - b;
- x = 4; }
- x = a + 3 * 90 - b; }}
However, I need some changes to be able to accept open round bracket "(" and close round bracket ")" for math expression such as:
- x = (x);
- x = a + ((3 * 90) - b);
- x = 4; }
- x = (((a + 3) * 90) - b); }}
Is there anyway I can edit my current implementation to accept open/close round bracket? There might still be expression with no round bracket. I do have rxOpen and rxClose which represent open and close round bracket as well but not sure how to insert it in.
rxAssign = regex("^\\s*(" + rxstrIdentifier + ")\\s*=\\s*((" + rxstrRef + ")((\\s*([\-+*])\\s*(" + rxstrRef + "))*))\\s*[;]\\s*([} ])*\\s*$");
where
string rxstrIdentifier = "\\b[a-zA-Z]\\w*\\b";
string rxstrConstant = "\\b\\d+\\b";
string rxstrRef = "(?:" + rxstrIdentifier + ")|(?:" + rxstrConstant + ")"; // identifier or constant
string rxOpen = "[(]";
string rxClose = "[)]";