WP Query – filtering terms with regex

This is untested, but give it a go. First get a list of the term names in the taxonomy. Then filter the returned array of names against your regex. Then use that filtered array of names for your WP query.

// assumes these assignments:
//
// $taxonomy - the taxonomy name you are querying against
// $regex - the regex to match the term names against

// First get all the terms that have posts:

$terms = get_terms( array(
    'taxonomy' => $taxonomy,
    'fields' => 'names', // return an array of term names
) );

$filtered_terms = preg_grep($regex, $terms);

// when you use this, expand $args with other relevant arguments for your query, such as post type:

$args = array(
    'tax_query' => array(
        array(
            'taxonomy' => $taxonomy,
            'field'    => 'name',
            'terms'    => $filtered_terms,
        ),
    ),
)

$the_query = new WP_Query( $args );

// Then run your loop