You could write a little, very simple routine that does it, without using a regular expression:
pos
so that is points to just before the opening bracket after your for
or while
. openBr
to 0
.pos
, reading the characters at the respective positions, and increment openBr
when 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 to 0
when your for
bracket closes. openBr
is 0
again.The stopping positon is your closing bracket of for(...)
. Now you can check if there is a semicolon following or not.