<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def wrap_query_in_nested_if_field_is_nested(query, field, nested_fields):
 """Helper for wrapping a query into a nested if the fields within the query are nested Args: query : The query to be wrapped. field : The field that is being queried. nested_fields : List of fields which are nested. Returns: (dict):
 The nested query """

    for element in nested_fields:
        match_pattern = r'^{}.'.format(element)
        if re.match(match_pattern, field):
            return generate_nested_query(element, query)

    return query