def get_flags(self, i, version0, scoped=False):
        """Get flags."""

        index = i.index
        value = ['(']
        version = False
        toggle = False
        end = ':' if scoped else ')'
        try:
            c = next(i)
            if c != '?':
                i.rewind(1)
                return None
            value.append(c)
            c = next(i)
            while c != end:
                if toggle:
                    if c not in _SCOPED_FLAGS:
                        raise ValueError('Bad scope')
                    toggle = False
                elif (not version0 or scoped) and c == '-':
                    toggle = True
                elif version:
                    if c not in _VERSIONS:
                        raise ValueError('Bad version')
                    version = False
                elif c == 'V':
                    version = True
                elif c not in _GLOBAL_FLAGS and c not in _SCOPED_FLAGS:
                    raise ValueError("Bad flag")
                value.append(c)
                c = next(i)
            value.append(c)
        except Exception:
            i.rewind(i.index - index)
            value = []

        return ''.join(value) if value else None
Get flags.