FastRoute icon indicating copy to clipboard operation
FastRoute copied to clipboard

Can I use regex without a variable? Can I use flags?

Open adjenks opened this issue 5 years ago • 3 comments

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?

adjenks avatar Feb 25 '20 00:02 adjenks

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');

adjenks avatar Feb 25 '20 00:02 adjenks

multiple route sections where you want to use regex force you to assign multiple junk variables though.

adjenks avatar Feb 25 '20 00:02 adjenks