def extractNotes(name, notes, legend=None, regex=None, key=lambda v: v):
    ''' This functions uses legend data to extract e.g. (1) references in a
        meal name and add these in full text to the notes.

        :param str name: The meal name
        :param list notes: The initial list of notes for this meal
        :param dict legend: The legend data. Use `None` to skip extraction. The
            key is searched inside the meal name (with the given regex) and if
            found the value is added to the notes list.
        :param re.compile regex: The regex to find legend references in the
            meal name. The regex must have exactly one group which identifies
            the key in the legend data. If you pass None the
            :py:data:`default_extra_regex` is used. Only compiled regex are
            supported.
        :param callable key: function to map the key to a legend key
        :rtype: tuple with name and notes'''
    if legend is None:
        return name, notes
    if regex is None:
        regex = default_extra_regex
    # extract note
    for note in list(','.join(regex.findall(name)).split(',')):
        if not note:
            continue
        note = key(note)
        if note in legend:
            if legend[note] not in notes:
                notes.append(legend[note])
        else:
            print('could not find extra note "{0}"'.format(note))
    # from notes from name
    name = regex.sub('', name).replace('\xa0', ' ').replace('  ', ' ').strip()
    return name, notes