Negative regular expression to match a domain URI WITHOUT a particular string [SOLVED]

[So I started writing this then solved my own problem but thought I’d share it incase it’s helpful to anyone else!]

I have two users for the same domain:

regular_user
for www.domain.com/anything/can/go/here?and&more

admin_user
same domain as above but with /manage/ ANYWHERE in it.

I’m trying to create a regular expression so that any webpage WITHOUT “manage” anywhere the URI is offered only the regular_user and any on the /manage/ page shows the admin_user.

I initially tried with something called a ‘negative lookahead’ that looks like this:

(?<!manage.*)

But this didn’t work. I thought maybe negative lookbehinds are not supported by Bitwarden.

I eventually found this which is a lookahead which appears to be supported:

https://www.domain.com(?!.manage.).*

This reads as: match the domain as usual but then after you get to “.com”, look ahead at the rest of the URI. If anything contains “manage” then the match fails, otherwise continue matching the rest of the string (that final .*).

Hope this helps someone else crack this scenario at some point.

All the best,
Dan

1 Like