You could write a little, very simple routine that does it, without using a regular expression:
- Set a position counter
posso that is points to just before the opening bracket after yourfororwhile. - Set an open brackets counter
openBrto0. - Now keep incrementing
pos, reading the characters at the respective positions, and incrementopenBrwhen you see an opening bracket, and decrement it when you see a closing bracket. That will increment it once at the beginning, for the first opening bracket in “for (“, increment and decrement some more for some brackets in between, and set it back to0when yourforbracket closes. - So, stop when
openBris0again.
The stopping positon is your closing bracket of for(...). Now you can check if there is a semicolon following or not.