'Return regex pattern for the format string.
Need to make sure that any characters that might be interpreted as
regex syntax are escaped.'

def pattern(self, format):

    processed_format = ''
    regex_chars = re_compile('([\\\\.^$*+?\\(\\){}\\[\\]|])')
    format = regex_chars.sub('\\\\\\1', format)
    whitespace_replacement = re_compile('\\s+')
    format = whitespace_replacement.sub('\\s+', format)
    while ('%' in format):
        directive_index = (format.index('%') + 1)
        processed_format = ('%s%s%s' % (processed_format, format[:(directive_index - 1)], self[format[directive_index]]))
        format = format[(directive_index + 1):]
    return ('%s%s' % (processed_format, format))
