import re


def get_pkg_from_body(body):
    """Extracts the pkg name from the given body.
    
    Arguments:
        body {dict} -- The body as extracted by `extract_body()`
    
    Note:
        https://stackoverflow.com/questions/40772067/regular-expression-matching-android-package-name

    Returns:
        str -- The pkg name if given. If there's an error extracting this
               or if the name is malformed, None is returned.
    """
    if 'pkg' in body:
        pkg = body['pkg']
        if re.match("^([a-zA-Z]{1}[a-zA-Z\d_]*\.)+[a-zA-Z][a-zA-Z\d_]*$", pkg):
            return pkg
    return None