Reject question marks after last / easy - use character class [^?] Instead . :
^/.+/[^?]+$
To reject people or dungen between two / s, you can use a negative scan . Since you want to reject /people/ but accept /peoples/ , the lookahead will look to the end of the line.
^/(?!(?:people|dungen)/.+$).+/.+$
Thus, the union of the two:
^/(?!(?:people|dungen)/[^?]+$).+/[^?]+$
Let the test.
>>> import re >>> r = re.compile(r'^/(?!(?:people|dungen)/[^?]+$).+/[^?]+$') >>> for s in ['/a/b/c/d', '/a/b', '/people/b/c/d', '/peoples/b/c/d', '/a/b/c?x=y']: ... print not not r.search(s) ... True True False True False
source share