How can I search for data if a template is specified in the database?

Are there templates like
abc????cba
or
??de??df
or any other combination.
But the user will enter the full line, for example, abc1234cba
, and the script needs to output all the lines where this combination exists, taking into account the templates.
Under the symbol ? any letter or number can be implied.

I’m doing it on WP, we’re looking for the ACF field
Have you tried this:


    $vin_regex = str_replace(array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'), '.', $vin_regex);

    
    $meta_query = array(
        array(
            'key' => 'vin',
            'value' => $vin_regex,
            'compare' => 'REGEXP', 
        ),
    );

    $args = array(
        'post_type' => 'product',
        'posts_per_page' => 10,
        'paged' => $paged,
        'meta_query' => $meta_query,
    );

    $query = new WP_Query($args);

It didn’t help

ave you tried this

    $query = "
        SELECT DISTINCT p.ID
        FROM {$wpdb->posts} p
        INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
        WHERE p.post_type = 'product'
          AND p.post_status = 'publish'
          AND pm.meta_key = 'vin'
          AND pm.meta_value LIKE REPLACE(%s, '?', '_')
        LIMIT 10 OFFSET %d
    ";

    $results = $wpdb->get_col($wpdb->prepare($query, $vin_input, $offset));

It didn’t help