Reputation: 1531
I use python Tornado, and I want extract from this URL:
http://myserver.com/v1/files_get/app/path/for/you/myfile.txt
this value:
app
and the rest of path (path):
/path/for/you/myfile.txt
I use this REGEXP for it into Tornado:
tornado.web.Application([
(r"/v1/files_get/(?P<root>[^\/]+)/?(?P<path>[^\/]+)?/?", files_get),
])
I don't know if it is possible, because my regexp only get only just level of path.
¿What should be the correct regex for it?
Upvotes: 0
Views: 552
Reputation: 444
Try this:
r'/v1/files_get/(?P<root>[^/]+)(?P<path>/.*)?'
/
is not magic, and you're not using it as a delimiter (as you would in Perl or Ruby), so it does not need to be escaped.
Since you want to capture everything after <root>, if it exists, you can make that whole group optional.
Upvotes: 1