javascript - How to match two strings to one route express.js -


i've got single route function want match 2 different paths to. idea create profile pages team members of website. they'll @ www.domain.com/name. issue is, people have nicknames. so, need www.domain.com/nickname go same place www.domain.com/name.

here's i've got far:

website.get('/name|nickname', websiteroutes.about); 

the problem things /asdasdfdnickname , /namezzzzzzzz match well.

how match either name or nickname without characters. believe called exclusive or?

so here working solutions

passing in ['/name', '/nickname'] routing function.

and john's answer below: /^\/?(name|nickname)\/?$/i

try /^\/?(name|nickname)\/?$/i match name/nickname only.

this regex means can optionally start forward slash, match "name" or "nickname" case insensitively, optionally allow forward slash @ end.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -