Regex for c++ for loop conditions

There’s no better way of explaining than with an example:
say I have a for loop:

for(int i = 0; i

I basically want a regex that groups i = 0, i, and i++ into three separate groups.

so far, i have this:

for\s*\(\s*[^\w\s]?(\w+=\d+)\s*;\s*([^;]+)\s*;\s*([^)]+)\s*\)\s*({)?

and it gives me the i and the i++ but due to the type specifier on the first part, it does not give me i = 0 and I’m not sure how to do it.

I also need to account for when there are no type specifiers at all. I basically want to skip the first word if there are two words before the =. Is this a possible regular expression?

Read more here: Source link