Slim 3 - Regex *RegExpression* for parameters *placeHolder* contains a capturing group

Hello again folks,

As the title says I having a problem with my routing, especially this one:

Note: Don’t mind the group here with a single EndPoint, there is a lot of EndPoints inside but showing them its not the foccus here.

 $this->group('/books/{books_id:(\d+,{0,1})*\d+}', function(){

            $this->get('',ResourceController::class . ':getSelectedResources');


and I got this error:

"message": "Regex \"(\\d+,{0,1})*\\d+\" for parameter \"books_id\" contains a capturing group"

My expected EndPoint is something like this:

GET - /api/books/1,2,3,4,5,…,n/pages

I have tested my Regular Expression at:

and used this exact expression: (\d+,{0,1})*\d+



try with this:

$this->group('/books/{books_id:[0-9]+}', function(){
            $this->get('',ResourceController::class . ':getSelectedResources');

This will generate the following route pattern:


and not



Apparantly capturing groups are not allowed, which is what you get by using parantheses. Instead you can use a non-capturing groups:

// note the use of (?: instead of ( in the regular expression
$this->group('/books/{books_id:(?:\d+,{0,1})*\d+}', function(){
   $this->get('', ResourceController::class . ':getSelectedResources');

Hope that helps,


1 Like

It works ! But its very strange thought. I’ll read further about this.

Thanks for your help ! Really appreciated!

The reason for this is that FastRoute internally compiles a regular expression to match all routes in one go. Capturing groups would break this.