import re
from typing import Dict


def _parse_group(pr_txt: str, header_pattern: str,
                 entry_regex: re.Pattern) -> Dict[str, int]:
    """General function to parse and extract a listing from the press release.
    Args:
        pr_txt: The text of the press release.
        header_pattern: A string representing a regex pattern uniquely
            identifying the top of the section.
        entry_regex: A regular expression to match all the groups in the
            section. This is expected to have a match group entitled "group"
            identifying the subset of the population and "count" to identify
            the tally identified with the group.
    Returns:
        A dictionary with keys being the groups in section and values being
        their associated counts.
    """
    output = {}
    listing = re.search(f'{header_pattern}.+?Under\s+Investigation', pr_txt)
    if listing:
        for row in entry_regex.finditer(listing.group()):
            output[row.group('group')] = int(row.group('count'))
    return output