def splitOnBrackets( expr, openStr='[', closeStr=']' ):
    """Splits expr in a sequence of alternating non-bracketed and bracketed expressions"""
    n = len( expr )
    components = []
    while len( expr ) > 0:
        n = len( expr )
        target = openStr
        if expr[0] == target: target = closeStr
        i = multifind( expr, [target] )
        if target == closeStr: i += 1
        components.append( expr[:i] )
        expr = expr[i:]
    return components
Splits expr in a sequence of alternating non-bracketed and bracketed expressions
recipes/Python/355531_Simple_patternbased_string/recipe-355531.py