Exclude words from expressjs route path

express, node.js

Solution

I used nested middleware to solve this.

router.use("/:group", function(req, res, next) {
  var excludes = ["api", "assets"];
  if (excludes.indexOf(req.params.group) !== -1) return next();
  else {
    router.use("/"+req.params.group, groupRouter);
    next();
  }
});

Problem

Is there a way to make it so this does not match `/api` and `/assets`? ``` router.use("/:group", groupRouter); ``` I tried the following but it didn't work. ``` router.use("/:group(!(api|assets))", groupRouter); ``` Also, I tried using a regex here but node gave me an error, saying it expected a callback rather than a regex. Note: apparently `.use` does not capture `group` either, but that isn't necessary in my case. I just need it to match everything except a few words.

Original source