Help with REGEX doesnt work on route path definition
I have this route definition:
Its basically a listener, every path under /auth should be handled by the auth.handler.
But I wanna exclude /auth/sign-up from this listener, I tried:
But this is not working. I also tried to add a route definition above this one, but this will make all the other routes stop working
10 Replies
the way you're using the lookahead isn't quite what you want
idk if you have a
/auth
route, that wouldn't be covered at all
but you're looking for something more like \/api(\/auth(?!\/sign-up)).*
i'm not a regex wiz, so there's probably a more efficient way to solvei find this app super helpful: https://regex101.com/
regex101
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
does this meet your needs? you should double-check the edge-cases:
\/api(\/auth(?!\/sign-up)).*
Still not working, idk why
ahhhhh
ok, so you actually need a union group
I could do this, but I dont wanna pass every possible value
hmmmm, what you mean?
but if I use the union, i will need to pass every possible value also, right?
as a general note, it's helpful to syntax-highlight your code by adding the language after the opening backticks:
```typescript
i'm talking about union capture groups (idk if that's their official name)
sorry, i'm going to need a sec to track this down; it's been a while since i did regex
I think I know what u mean, but if I use the union, i will need to pass every possible value also, right?
you shouldn't
gotem
\/api\/auth\/(?!sign-up$).*
i didn't realize you specifically wanted to exclude the /sign-up
endpoint, but not any sub-routes
so the union turned out to be overkill