def reg_extract(openfield, address):
    """
    Extract data from openfield. 'ip:port:pos' or with option 'ip2:port:pos2,reward=bis2a'

    :param openfield: str
    :param address: str
    :return: tuple (ip, port, pos, reward)
    """
    options = {}
    if "," in openfield:
        # Only allow for 1 extra param at a time. No need for more now, but beware if we add!
        parts = openfield.split(",")
        openfield = parts.pop(0)
        for extra in parts:
            key, value = extra.split("=")
            options[key] = value
    ip, port, pos = openfield.split(":")
    reward = options["reward"] if "reward" in options else address
    source = options["source"] if "source" in options else None
    if source and source != address:
        raise ValueError("Bad source address")
    return ip, port, pos, reward