How do I write a RESTful url regex in GAE / Python for n parameters?
I currently have three URL paths that show up in the ServiceHandler. How can I combine three into one neat regex that can pass n number of arguments to the ServiceHandler?
(r'/s/([^/]*)', ServiceHandler),
(r'/s/([^/]*)/([^/]*)', ServiceHandler),
(r'/s/([^/]*)/([^/]*)/([^/]*)', ServiceHandler)
+2
source to share
3 answers
(r'^/s/(([^/]*)((/[^/]+)*))$', ServiceHandler)
Gotta do the trick to fit any number
/ s / foo / bar / baz / to / infinity / and / beyond /
You can also limit it to a range by doing something like
^/s/(([^/]*)((/[^/]+){0,2}))$
It will only match what you like
/s/foo/bar/baz
/s/foo/bar
/s/foo
but not
/s/foo/bar/baz/pirate
/s
+1
source to share