What you are looking for is support for globbing (https://github.com/begin/globbing#wildcards). Unfortunately, Drupal does not support globbing out of the box.
In modern globbing implementation, *
would match on any character but /
, and **
would match on any character, including /
.
In order to implement this support, one would need to:
Look how PathMatcher
(core/lib/Drupal/Core/Path/PathMatcher.php) service matches the path.
Extend it into own custom service where only matchPath()
will be overridden.
Replace the content of matchPath()
with the code below (this is a copy of the original matchPath()
with some alterations).
Alter included service to use your custom path matching (for block only or whole site).
Update configuration of blocks to use **
for full path matching and *
for subpath only.
/**
* {@inheritdoc}
*/
public function matchPath($path, $patterns) {
if (!isset($this->regexes[$patterns])) {
// Convert path settings to a regular expression.
$to_replace = [
// Replace newlines with a logical 'or'.
'/(\r\n?|\n)/',
'/\\\\\*\\\\\*/',
// Quote asterisks.
'/\\\\\*/',
// Quote <front> keyword.
'/(^|\|)\\\\<front\\\\>($|\|)/',
];
$replacements = [
'|',
'.*',
'[^\/]*',
'\1' . preg_quote($this->getFrontPagePath(), '/') . '\2',
];
$patterns_quoted = preg_quote($patterns, '/');
$this->regexes[$patterns] = '/^(' . preg_replace($to_replace, $replacements, $patterns_quoted) . ')$/';
}
return (bool) preg_match($this->regexes[$patterns], $path);
}
Note that this code only adds additional token replacement **
and alters what *
token does (any character but /
).