Regular Expressions in Python - match all that does not contain... (App Engine)
Just started using App Engine's webapp framework, but I can't figure out what's wrong with this:
My URL structure is set up to where any pages are prefixed with /x/ . For example..
http://site.com/x/my_account
http://site.com/x/profile
http://site.com/x/admin
etc etc....
Now I want to be able to match NOT prefixed with /x/ to be handled by another handler. This will be a user's page.
EX:
http://site.com/user1
http://site.com开发者_如何转开发/user2
Here's my WSGI Application
application = webapp.WSGIApplication([
('/((?!/x/).)*$', Profile.ProfileMainHandler),
('/x', Misc.MainHandler),
('/x/', Misc.MainHandler),
('/x/videos', Videos.VideoHandler),
('/x/videos/add', Videos.VideoAddHandler),
# etc etc, many more to list...
Why is this not working? The /x/etc handlers work fine, but instead of anything else going to Profile.ProfileMainHandler, it doesn't match anything.
As always thank you for your patience!
It should be like this:
'^/(?!x/|x$).*$'
URLs are matched in order, from first to last. Simply add a .*
regular expression after all URL patterns that match /x
.
精彩评论