import re


def get_existing_value(key_value_regex_string, string_to_search):
    """Helper method to get the value of an existing environment variable

    Inputs:
        - key_value_regex_string (String): A regex string consisting of the existing key to search for
        - string_to_search (String): String used to search for the key_value_regex_string in

    Returns:
        - The existing keys value
        - None if the existing key does not exist
    """
    existing_value = None
    search_object = re.search(key_value_regex_string, string_to_search)
    if search_object:
        existing_key_value_string = string_to_search[search_object.start():search_object.end()].rstrip()
        existing_value = existing_key_value_string.split('=')[1].strip('"')

    return existing_value