Routing set regex patterns for single characters

I must create short slug routing that contain only one character [a-z] ( as post/a )or 0-9 ( as post/0-9 )

not working when try “right syntax”:

->setPatterns(['alfanum' => '^[a-z]$|^0-9$'])

but work when try (i´m not sure if this matching only one char)

->setPatterns([‘alfanum’ => ‘[a-z]|0-9’])

Why and how to ?

if you want just to match 1 char its with selector {1}


$routes->connect('/:slug')->setPatterns(['slug' => '[0-9a-z]{1}']);

you can check if route is ok for you you can use

 php bin/cake.php routes check /a