I want a super simple filter in nodejs express routing path. The param must be word1 or word2. Tested in: https://forbeslindesay.github.io/express-route-tester/
with expression: test/:gender(\b(word1|word2)\b)
path: test/word2
And all works well. "The path matches the route"
But in code:
router.get('^/test/:gender(\b(word1|word2)\b)', function (req, res, next){//something})...;
I got 404(redirects from express, as it should if the param is not correct!).
Note 1: removing the regex string, it works.
Note 2: another filter I DID managed to make it work. It has to be like: "word1-word2[-moreWords]. I implemented it with
router.get('^/test/:user_name(*[a-zA-Z0-9][-]*[a-zA-Z0-9])', function (req, res, next) {//something});
and works without problem.
Note 3: I also test it (I write them first in:) https://regex101.com/ and, of course, they work.
So what do I do wrong?
'^/test/:gender(word1|word2)\\b'or'^/test/:gender(word1|word2)\b'