import re


def format_agent_config_string(string):
    """
    Takes a string from the agent config template and formats it for output in
    agent_config shortcode.
      - If string contains exactly one '#' and no alphabetic characters, 
        remove the '#' and any new line characters.
      - If the string contains exactly one '#' and has alphabetic characters, 
        remove the '#' (this represents a config key/value)
    """
    # Match any lines containing strictly one '#' character that can have any
    # number of leading or trailing whitespaces, and no words.
    # Matching lines in the config template file are for spacing only.
    regex_string = r"[^a-zA-Z0-9#]*#[^a-zA-Z0-9#]*$"

    if re.match(regex_string, string):
        return string.replace('#', '').replace('\n', '').strip()
    elif '#' in string and '##' not in string:
        return string.replace('# ', '') + '\n'
    else:
        return string + '\n'