+ // we will alloc the array later (only if really needed) but count
+ // the number of sub-expressions in the regex right now
+
+ // there is always one for the whole expression
+ m_nMatches = 1;
+
+ // and some more for bracketed subexperessions
+ for ( const wxChar *cptr = expr.c_str(); *cptr; cptr++ )
+ {
+ if ( *cptr == _T('\\') )
+ {
+ // in basic RE syntax groups are inside \(...\)
+ if ( *++cptr == _T('(') && (flags & wxRE_BASIC) )
+ {
+ m_nMatches++;
+ }
+ }
+ else if ( *cptr == _T('(') && !(flags & wxRE_BASIC) )
+ {
+ // we know that the previous character is not an unquoted
+ // backslash because it would have been eaten above, so we
+ // have a bare '(' and this indicates a group start for the
+ // extended syntax. '(?' is used for extensions by perl-
+ // like REs (e.g. advanced), and is not valid for POSIX
+ // extended, so ignore them always.
+ if ( cptr[1] != _T('?') )
+ m_nMatches++;
+ }
+ }