Checks whether the html_doc contains a meta matching the prefix & code

def search_meta_tag(html_doc, prefix, code):
    """
    Checks whether the html_doc contains a meta matching the prefix & code
    """
    regex = '<meta\s+(?:name=([\'\"]){0}\\1\s+content=([\'\"]){1}\\2|content=([\'\"]){1}\\3\s+name=([\'\"]){0}\\4)\s*/?>'.format(prefix, code)
    meta = re.compile(regex, flags=re.MULTILINE | re.IGNORECASE)
    m = meta.search(html_doc)
    if m:
        head = re.search(r'</head>', html_doc, flags=re.IGNORECASE)
        if head and m.start() < head.start():
            return True
    return False