import re


def increment_name(name):
    """If `name` does not already end in a number, add "_2" to it.

    Otherwise, increase the number after the underscore.
    """
    match = re.search('_([0-9]+)$', name)
    prev_number = 1
    if match:
        prev_number = int(match.group(1))
        # remove the entire _$number part from the name
        name = name[:len(name) - len(match.group(0))]

    name += '_%d' % (prev_number + 1)
    return name