import re


def increment_bar_number(line, increment):
    """Increments a bar number (if found) on a line and returns the line."""
    # skip some stuff if it isn't relevant
    if '\\barNumberCheck #' not in line and '%' not in line:
        return line
    # this regex actually finds the numbers and makes groups
    regex_num = re.compile(r"\s([#%]\s?)(\d+)")
    num = regex_num.search(line)

    if num:
        n = int(num.group(2))
        n = n + increment
        line = regex_num.sub(r' ' + num.group(1) + '{}'.format(n), line)

    # return line whether or not it has been touched
    return line