import re


def extract_succeed_results(cmd, regex, py_type=int, dict_key='stdout'):
    """Extract the values of the succeed results
    
    Parameters
    ----------
    cmd : dict
        The Benchpress command to extract from
    regex : str
        The regex that extract a value from each result
    py_type : type
        The Python type of the extracted 
    dict_key : str
        The dictionary key to extract from

    Returns
    -------
    values : list
        List of extracted values
    """
    ret = []
    for job in cmd.get('jobs', []):
        for res in job.get('results', []):
            match_list = re.findall(regex, res[dict_key])
            if res['success'] and len(match_list) > 0:
                for match in match_list:
                    ret.append(py_type(match))
    return ret