import re


def _get_enclosed_str(text, prefix, suffix):
    """
    Remove prefix and suffix from the string if the string contains both prefix and suffix.
    """
    success = False
    text = text.strip()
    pattern = f"^{prefix}.+{suffix}$"
    if re.search(pattern, text):
        pattern1 = f"^{prefix}"
        pattern2 = f"{suffix}$"
        text = re.sub(pattern1, "", text)
        text = re.sub(pattern2, "", text)
        success = True
    return text, success