import re


def inspect_file(filename, pattern):
    """
    Inspects file for regex patterns required by other functions.

    Parameters:
    -----------
    filename: str
        location of Gaussian log file
    pattern: str
        the regex pattern to look for within the file

    Returns:
    --------
    check: bool
        Indicates the presence of the specific regex pattern in the log file.
    """
    with open(filename, "rt") as file:  # opens file
        text = file.read()  # reads file into string
        if (
            pattern == r"(^.*?Converged\?(?:\n.*(YES)){4})"
        ):  # pattern for the item convergence table
            check = bool(
                re.search(pattern, text, re.MULTILINE)
            )  # the regex search needs to be a multiline search.
        else:  # if not
            check = bool(
                re.search(pattern, text)
            )  # regex is a normal search with no flags.
        return check