def flag_topics(df, phrases_by_name):
    """
    Flag phrases in the messages as specified by a regular expression.

    Args:
        df: DataFrame containing messages as created by transform_dataframe().
        phrases_by_name: dict of regex expressions used to identify topics.

    Returns:
         DataFrame with new columns, named after each key in phrases_by_name
         with the suffix '_related' which flag whether the topic is mentioned
         in the message.

    """
    for name, phrases in phrases_by_name.items():
        df[name + '_related'] = df.body.str.contains(phrases, case=False)
    return df