from typing import Optional
import re


def _env_var(string: str) -> Optional[str]:
    """Return a value between curly braces, if detect `%ENV{}` pattern.

    Parameters
    ----------
    string: str
        String to check

    Returns
    -------
    Optional[str]
        Return env variable name if the pattern is detected
    """
    if not isinstance(string, str):
        string = str(string)
    pattern = re.compile(r"^%ENV{(?P<env_name>[a-zA-Z0-9]+[a-zA-Z0-9_-]*)}$")
    match = pattern.fullmatch(string)
    return match.group("env_name") if match else None