'Returns a tuple (reverse string, group count) for a url.
For example: Given the url pattern /([0-9]{4})/([a-z-]+)/, this method
would return (\'/%s/%s/\', 2).'

def _find_groups(self):

    pattern = self.regex.pattern
    if pattern.startswith('^'):
        pattern = pattern[1:]
    if pattern.endswith('$'):
        pattern = pattern[:(-1)]
    if (self.regex.groups != pattern.count('(')):
        return (None, None)
    pieces = []
    for fragment in pattern.split('('):
        if (')' in fragment):
            paren_loc = fragment.index(')')
            if (paren_loc >= 0):
                pieces.append(('%s' + fragment[(paren_loc + 1):]))
        else:
            try:
                unescaped_fragment = re_unescape(fragment)
            except ValueError as exc:
                return (None, None)
            pieces.append(unescaped_fragment)
    return (''.join(pieces), self.regex.groups)
