Skip to content

named groups in regex routers not supported? #4277

Description

@its-dibo
// /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)

Activity

  1. dougwilson commented on May 14, 2020

    @dougwilson
    Contributor

    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

  2. added this to the 5.0 milestone on Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions