import re


def flow_split(expr):
    """
    splitting the stock expressions to extract the flow namespace

    expr is INTEG (inflow-outflow,init stock)

    returns:
    - flows: ['inflow', 'outflow']
    - flow: inflow-outflow
    - init: init stock)

    :param expr: expr expression from translation routine (everything right of the equation sign)
    :return: list of flows, flow expression and init expression
    """
    # eliminating the INTEG ( part
    expr = expr.split('(', 1)[-1]
    # splitting the init off the expression
    flow, init = expr.rsplit(',', 1)
    # splitting the flows off, but avoiding splits between parentheses
    flows = re.split('(".*?")|[+-/*]', flow)
    # removing empty strings in flows
    flows = [x for x in flows if x is not None]
    flows = [x for x in flows if x != '']
    flows = [x.strip() for x in flows]
    # removing the closing parenthesis from the init expression
    init = init.replace(')', '')
    return flows, flow, init