private bool Balance (int gid, int balance_gid, bool capture, int ptr) {
int b = groups [balance_gid];
if(b == -1 || marks[b].Index < 0) {
//Group not previously matched
return false;
}
Debug.Assert (marks [b].IsDefined, "Regex", "Balancng group not closed");
if (gid > 0 && capture){
Open (gid, marks [b].Index + marks [b].Length);
Close (gid, ptr);
}
groups [balance_gid] = marks[b].Previous;
return true;
}