<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def name_replace(records, search_regex, replace_pattern):
 """ Given a set of sequences, replace all occurrences of search_regex with replace_pattern. Ignore case. If the ID and the first word of the description match, assume the description is FASTA-like and apply the transform to the entire description, then set the ID from the first word. If the ID and the first word of the description do not match, apply the transform to each individually. """

    regex = re.compile(search_regex)
    for record in records:
        maybe_id = record.description.split(None, 1)[0]
        if maybe_id == record.id:
            record.description = regex.sub(replace_pattern, record.description)
            record.id = record.description.split(None, 1)[0]
        else:
            record.id = regex.sub(replace_pattern, record.id)
            record.description = regex.sub(replace_pattern, record.description)
        yield record