New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to get named keys with a negative look ahead? #252
Comments
Unfortunately, I was never able to make it works as you want. I also have a situation where this would be needed. |
After some investigation, I found out that this seems to work: |
@DavidHenri008 has the right idea. This falls under "Custom Matching Parameters" in the docs. Essentially, you can put a regex in parenthesis after a named parameter in order to define a custom regex. |
Actually I'll reopen this, I realize now the real issue was you couldn't start a regex with The logic was I believe added in #207 and the code itself throwing is https://github.com/pillarjs/path-to-regexp/blob/master/src/index.ts#L85 |
@jonchurch thoughts on what should be changed if this is an open issue? From the implementation POV it’s not a valid regex to start with the |
@blakeembrey The best way to prevent someone running into this mistake is likely adding an example to the docs. Thinking about it, a change to the error message is overkill here. Specifically, adding an example for lookahead/behinds. |
Hey @blakeembrey @jonchurch . What's the resolution here. I ran into a similar use case to negate out urls based on a specific keyword occurrence. something like |
Bump this. I'm trying to write a regex that excludes a path starting with |
I ran into this (bug?) today with this vercel.json. Any idea what the fix is here?
|
I think I've probably ran into the same issue while trying to use negative lookaheads combined with path params, the way vercel recommends doing this in the nextjs docs: export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)',
],
} My issue is trying the example with path params and expecting it to work: '/((?!foo/:bar))' turns into /^(?:\/((?!foo\/:bar)))[\/#\?]?$/i instead of the expected /^(?:\/((?!foo(?:\/([^\/#\?]+?)))))[\/#\?]?$/i |
@royeden You can’t put named keys inside the regex, regardless of it being a negative lookahead. |
say i have a request with a url
how can I match anything except "foo" while having the first parameter be a named key?
The text was updated successfully, but these errors were encountered: