Equivalent regex without negative lookahead

140 Views Asked by At

I am trying to setup a Traefik RedirextRegex middleware. But since that uses Golang's STD re lib, it does not support negative lookaheads (?!).

All but the following URLs must be redirected:

https://example.com/whatever/else
https://example.com/application/o/authorize/
https://example.com/application/o/authorize/Rand0m
https://example.com/application/o/authorize/Rand0m?abc=123
https://example.com/application/o/RaNd0m/end-session/
https://example.com/application/o/RaNd0m/end-session/Rand0m
https://example.com/application/o/RaNd0m/end-session/Rand0m?abc=123

I've come up with this regex:

^https?://[^/]+/application/o/(?!authorize|.*/end-session).*$

But because negative lookahead is not supported, I cannot use it.

For completeness, here are some expected URLs that must be redirected:

https://example.com/application/o/RaNd0m/
https://example.com/application/o/RaNd0m/Rand0m
https://example.com/application/o/token/
https://example.com/application/o/token/Rand0m
https://example.com/application/o/userinfo/
https://example.com/application/o/userinfo/Rand0m
https://example.com/application/o/introspect/
https://example.com/application/o/introspect/Rand0m
https://example.com/application/o/revoke/
https://example.com/application/o/revoke/Rand0m
https://example.com/application/o/device/
https://example.com/application/o/device/Rand0m
https://example.com/application/o/RaNd0m/jwks/
https://example.com/application/o/RaNd0m/jwks/Rand0m

Is it possible to keep the same meaning but use only features supported by Golang's re lib?

0

There are 0 best solutions below