import re


def fix_grams(ret_str):
    """
    Search for gram strings that have been split with whitespace and rejoin them.

    For instance "3 SG" will become "3SG"
    """
    for gram in ['3SG', '1PL', '2SG', '2PL']:
        for i in range(1, len(gram) + 1):
            first, last = gram[:i], gram[i:]

            if first and last:
                expr = '%s\s+%s' % (first, last)
                ret_str = re.sub(expr, gram, ret_str, flags=re.I)
    return ret_str