0

Do regular expressions in Express routing work the same as normal Javascript regexs? I am trying to match routes that look like either "/users" or "/blah/users"

I also want to capture the blah part if it exists. I came up with this regular expression to do the job:

/^(?:\/)(?:(\w+)(?:\/))?(?:\busers\b)$/

I tested the regex here and it works fine:

https://regex101.com/r/zS3nH5/2

However, when I put it into my app.get route it never matches:

app.get('/^(?:\/)(?:(\w+)(?:\/))?(?:\busers\b)$/', function(req, res) {
    // do stuff
});
millarnui
  • 549
  • 1
  • 6
  • 17

0 Answers0