def ansi_split(text, _re=re.compile(u"(\x1b\\[(\\d*;?)*\\S)")):
    """Yields (is_ansi, text)"""

    for part in _re.split(text):
        if part:
            yield (bool(_re.match(part)), part)
def ansi_split ( text , _re = re . compile ( u"(\x1b\\[(\\d*;?)*\\S)" ) ) : for part in _re . split ( text ) : if part : yield ( bool ( _re . match ( part ) ) , part )
Yields (is_ansi, text)