express icon indicating copy to clipboard operation
express copied to clipboard

named groups in regex routers not supported?

Open its-dibo opened this issue 4 years ago • 1 comments

// /regex/hello -> matches
app.get(/\/regex\/(.+)/, (req, res) => res.json({ params: req.params }));

//named groups not suppoted?
//  /regex/hello -> error
app.get(/\/regex2\/(?<groupname>.+)/, (req, res) =>
  res.json({ params: req.params })
);

when using named capture groups, I got the following error

TypeError: Cannot read property 'name' of undefined
    at Layer.match (webpack:///./node_modules/express/lib/router/layer.js?:147:20)
    at matchLayer (webpack:///./node_modules/express/lib/router/index.js?:574:18)
    at next (webpack:///./node_modules/express/lib/router/index.js?:220:15)
    at cors (webpack:///./node_modules/cors/lib/index.js?:188:7)
    at eval (webpack:///./node_modules/cors/lib/index.js?:224:17)
    at originCallback (webpack:///./node_modules/cors/lib/index.js?:214:15)
    at eval (webpack:///./node_modules/cors/lib/index.js?:219:13)
    at optionsCallback (webpack:///./node_modules/cors/lib/index.js?:199:9)
    at corsMiddleware (webpack:///./node_modules/cors/lib/index.js?:204:7)
    at Layer.handle [as handle_request] (webpack:///./node_modules/express/lib/router/layer.js?:95:5)
    at trim_prefix (webpack:///./node_modules/express/lib/router/index.js?:317:13)
    at eval (webpack:///./node_modules/express/lib/router/index.js?:284:7)
    at Function.process_params (webpack:///./node_modules/express/lib/router/index.js?:335:12)
    at next (webpack:///./node_modules/express/lib/router/index.js?:275:10)
    at urlencodedParser (webpack:///./node_modules/body-parser/lib/types/urlencoded.js?:91:7)
    at Layer.handle [as handle_request] (webpack:///./node_modules/express/lib/router/layer.js?:95:5)

its-dibo avatar May 14 '20 23:05 its-dibo

No, they are not supported, but no reason why support cannot be added 👍 . If you (or anyone else) would like to add support for this, please go ahead and open a pull request against our router engine code: https://github.com/pillarjs/router

dougwilson avatar May 14 '20 23:05 dougwilson