<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _check_and_expand_exponential(expr, variables, data):
 """Check if the current operation specifies exponential expansion. ^^6 specifies all powers up to the 6th, ^5-6 the 5th and 6th powers, ^6 the 6th only."""

    if re.search(r'\^\^[0-9]+$', expr):
        order = re.compile(r'\^\^([0-9]+)$').findall(expr)
        order = range(1, int(*order) + 1)
        variables, data = exponential_terms(order, variables, data)
    elif re.search(r'\^[0-9]+[\-]?[0-9]*$', expr):
        order = re.compile(r'\^([0-9]+[\-]?[0-9]*)').findall(expr)
        order = _order_as_range(*order)
        variables, data = exponential_terms(order, variables, data)
    return variables, data