FastRoute
FastRoute copied to clipboard
Can I use regex without a variable? Can I use flags?
Regex with no variable:
$r->addRoute('GET', '/{user|person}', 'get_user_handler');
Case insensitive flag:
$r->addRoute('GET', '/{/user/i}', 'get_user_handler');
I tried both, they did not work. Am I doing it wrong?
My current workaround for both is to make a variable with a name I won't collide with, and use a 'mode modifier', eg.(?i), which I was unaware existed until this use case.
Example:
$r->addRoute('GET', '/{junk_variable:(?i)user}', 'get_user_handler');
multiple route sections where you want to use regex force you to assign multiple junk variables though.