import re


def _compile_regex(string):
    """Generate the regex for label checking"""
    # Escape * for T2*
    if string == 'T2*':
        string = 'T2\*'
        regex = re.compile(r"(\b%s\b)|(_%s_)|(_%s)|(%s_)|(t2star)" % (string,string,string,string), re.IGNORECASE)
    # Prevent T2 from capturing T2*
    elif string == 'T2':
        regex = re.compile(r"(\b%s\b)|(_%s_)|(_%s$)|(%s_)" % (string,string,string,string), re.IGNORECASE)
    else:
        regex = re.compile(r"(\b%s\b)|(_%s_)|(_%s)|(%s_)" % (string,string,string,string), re.IGNORECASE)
    return regex