import re


def get_two_mismatches_loc(g_ob, g_ex):
    """ Given a observed protospacer vs expected protospacer, if 1-2 mismatches, output the position
        of mismatches starting from the PAM-distal end.

        :param g_ob: observed protospacer
        :param g_ex: expected protospacer
        :return: [position A, position B] corresponds to two mismatches at positions A and B
                 [position A, -1] corresponds to a site with 1 mismatch at position A
                 [-1, -1] corresponds to either no mismatches or >2 mismatches
    """
    wlist = [x + 1 if g_ob[j] != g_ex[j] else x for j, x in enumerate([0] * len(g_ex))]
    glen, nmm = len(g_ex), sum(wlist)
    if 1 <= nmm <= 2:
        mminds = [i.start() for i in re.finditer('1', "".join(list(map(str, wlist))))]
        if nmm == 1:
            return [glen - mminds[0], -1]
        else:
            return [glen - mminds[0], glen - mminds[1]]
    else:
        return [-1, -1]