You can use /(^[a-z]{3}(?:,[a-z]{3})*$)/
to get the comma separated string, as a unique response, where you can split the results latter.
Alternatively, if you need regex to split them for you, you may use something like /,?([a-z]{3}),?/g
. But I don't know how to enable the global flag in the routes, and it would also accept things like ,hey,you
or hey,you,
.
However, express route regex uses it's own regex rules with path-to-regexp package that doesn't allow catching groups (?:)
, and then, you can not define any repetition pattern as you need.
So it looks like the only way to make repetitions is with *
(zero or more) or +
(one or more), after the key name, so we could use something like /:id+([a-z]{3},?)
where you can enable strict, sensitive and end.
You can test your regex paths with the Express Route Tester.
So it would be something like:
router.get('/:id+([a-z]{3},?)', (ctx) => {
ctx.status = 200;
})
You may need to post-process the id to remove the ,
.
Another alternative would be using a middleware.