def METHOD_NAME(cls, text):
    match = None
    def rep_f(m):
        nonlocal match
        match = m
        return ''
    new_text = cls._sphinx_directive_re.sub(rep_f, text)
    return new_text, match.group(1) if match else None