def search_for_intervals(input: str) -> str:
    """
    Extract the interval in the answer
    For example:
        The answer is: (-\infty, 0) \cup (1, +\infty) and [1, 2]. --> ['(-\infty, 0) \cup (1, +\infty)', '[1, 2]']
    """
    latex_objects = Word(alphanums + "+ - * / ^ | % $ ! \\ { }")
    left_bracket = oneOf("[ (")
    right_bracket = oneOf("] )")
    space = Optional(" ")
    interval = (
        left_bracket
        + latex_objects
        + space
        + ","
        + space
        + latex_objects
        + right_bracket
    )
    intervals = Combine(
        delimitedList(interval, delim=space + "\\cup" + space, combine=True)
    )

    result = intervals.searchString(input)
    return [_[0] for _ in result]

    Extract the interval in the answer
    For example:
        The answer is: (-\infty, 0) \cup (1, +\infty) and [1, 2]. --> ['(-\infty, 0) \cup (1, +\infty)', '[1, 2]']
    
envs/rstar/eval_src/toolkit_for_MATH/parsing_lib.py