How do I use PathMatcher::matchPath() for a wildcard path?
In your sample you were comparing the internal path (/node/123) with a path alias pattern (/topic/*). This won't work. You need to do the matching with the path alias instead.

/**
 * Implements template_preprocess_html().
 */
function MYTHEME_preprocess_html(&amp;$variables) {
  $current_path = \Drupal::service('path.current')-&gt;getPath();
  $current_alias = \Drupal::service('path.alias_manager')-&gt;getAliasByPath($current_path);
  if (\Drupal::service('path.matcher')-&gt;matchPath($current_alias, '/topic/*')) {
    $variables['attributes']['class'][] = 'is-topic';
  }
}


You could achieve the same by exploding the current request URI and then see if the first key is topic.

/**
 * Implements template_preprocess_html().
 */
function MYTHEME_preprocess_html(&amp;$variables) {
  $request_uri = ltrim(\Drupal::request()-&gt;getRequestUri(), '/');
  $args = explode('/', $request_uri);
  if (isset($args[0]) &amp;&amp; $args[0] === 'topic') {
    $variables['attributes']['class'][] = 'is-topic';
  }
}