'Helper method to translate the search string into a regular
expression
@param string: the search string'

@classmethod
def translate(cls, string):

    if (not string):
        return None
    match = False
    output = []
    append = output.append
    GROUPS = cls.GROUPS
    ESCAPE = cls.ESCAPE
    escaped = False
    for character in s3_unicode(string).lower():
        result = None
        if (not escaped):
            if (character == '\\'):
                escaped = True
                continue
            elif (character == '%'):
                result = '.*'
            elif (character == '_'):
                result = '.'
        if (result is None):
            if (character in ESCAPE):
                result = ('\\%s' % character)
            else:
                result = character
                for group in GROUPS:
                    if (character in group):
                        match = True
                        result = ('[%s%s]{1}' % (group, group.upper()))
                        break
        if (escaped and (character not in ('%', '_'))):
            result = ('\\%s' % result)
        escaped = False
        append(result)
    return (''.join(output) if match else None)
