import re


def substitute(line, regex, class_):
    """Generate a span and put it in the line per the regex."""
    result = re.search(regex, line)
    if result:
        for match in result.groups():
            line = line.replace(
                match, '<span class="{}">{}</span>'.format(class_, match), 1
            )
    return line