The simplest solution is to get all the existing rewrite rules, match the requested URl to one of them, and then convert it into a query.
Like so:
// Get all the rewrite rules
global $wp_rewrite;
$url_path = "2020/04/test-post"; // Or "tag/whatever" or "feed/atom" etc
// Match the URL against WordPress rewrite rules
$rewrite_rules = $wp_rewrite->wp_rewrite_rules();
$matched_rule = false;
foreach ( $rewrite_rules as $pattern => $query ) {
if ( preg_match( "#^$pattern#", $url_path, $matches ) ) {
$matched_rule = $query;
break;
}
}
// Replace each occurrence of $matches[N] with the corresponding value
foreach ( $matches as $key => $value ) {
$matched_rule = str_replace( "\$matches[{$key}]", $value, $matched_rule );
}
// Turn the query string into a WordPress query
$query_params = array();
parse_str(
parse_url( $matched_rule, PHP_URL_QUERY),
$query_params
);
// Construct a new WP_Query object using the extracted query parameters
$query = new WP_Query($query_params);