I originally had this route for matching any clientId
after /c
which worked great because I didn't have to worry about static files, ajax endpoints, or any other pages.
app.get('/c/:clientId'
The request came in to get rid of the /c
for vanity purposes so I tried my best to do negated lookaheads for static files, etc (?!css\\/|js\\/|...
at the same time doing a capture group (.*)
to get the actual value for req.params[0]
.
Unfortunately, I wasn't able to capture the value "up to" the first forward and ended up using (\\w*)
as the capture workaround. However, this only grabs /client123
/client123/item/e0980780-efac-11e3-ac10-0800200c9a66
but not /some-super-duper-client5000
/some-super-duper-client5000/item/e0980780-efac-11e3-ac10-0800200c9a66
Please see example here:
Any insight would be appreciated!
I'm not 100% clear on what you want to capture vs. what you don't want to capture, but perhaps using this would work for your capturing group?:
([^\/]*)
This would be the end result regular expression:
^\/(?!css\/|views\/|js\/|image\/|endpoint\/|style-guide)([^\/]*)$
Live example:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.