The greedy star (*
) and the trailing star (**
) are path segment operators, they will match the rest of the path segments, they do not match parts of a segment, so yes, a slash is required.
You can use regular expressions for custom route elements to achieve what you're looking for:
$builder
->connect('/{key}', ['controller' => 'Api', 'action' => 'aAction'])
->setPatterns(['key' => 'a[a-z0-9]+'])
->setPass(['key'])
->setHost('domain.world');
$builder
->connect('/{key}', ['controller' => 'Api', 'action' => 'bAction'])
->setPatterns(['key' => 'b[a-z0-9]+'])
->setPass(['key'])
->setHost('domain.world');
$builder
->connect('/{key}', ['controller' => 'Api', 'action' => 'cAction'])
->setPatterns(['key' => 'c[a-z0-9]+'])
->setPass(['key'])
->setHost('domain.world');
See also
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…