RegEx in routing params

Some syntax sugar. Would be cool, if express would parse RegEx’s as a part of routing paths.



Eveything in the braces should be parsed as a RegEx. That way more complex, but sweetend, paths could be built. 🙂

I know, that you can pass in RegEx’s as a path, but then you’ll end up with req.params as an array.

Yeah or No? Maybe I’ll make a PR.

Author: Fantashit

1 thought on “RegEx in routing params

  1. Hmm.

    Isn’t app.param used for this? Of course app.param callbacks will execute for each route but if you want it only for a specific route, just add another middleware before you main callback and if the parameter doesn’t match your regex run next('route').

    app.get("/page/:page", function(req, res, next) {
      if  (!/^[0-9]+$/.test( next('route');
    }, function(req, res, next){
      //...code that only run when `page` parameter is a integer

Comments are closed.