def get_arg(instr, var):
    """Returns the bracketed argument that immediately follows the first
        occurance of the 'var' string, along with the entire expression
        for easy replace

        example:
        >>> instr = "some text $var['user'] more text"
        >>> get_arg(instr,'$var')
        ("$var['user']", 'user')
    """
    s = len(var) + 1
    i = instr.find(var + '[')
    if i != -1:
        o = instr.find(']', i + s)
        if o != -1:
            arg = instr[i + s:o].strip('"\'')
            exp = instr[i:o + 1]
            return exp, arg
        else:
            return '', ''
    else:
        return '', ''
