I have a URL binded to a handler in Tornado. e.g.
(r'/browse/article/([a-zA-Z0-9_-]+)/([0-9]*)', ArticleHandler),
However, the number of arguments is not fixed, such that some will be /browse/article/blah, others will be /browse/article/blah/2. In other words, the last argument may or may not exist.
Is it still possible to use a single handler to handle this case? If so, how should I formulate the regex string to match all possible cases?
Try this:
This makes the last segment optional while keeping the capturing parentheses intact, in case they are used for something later.