I've seen some URLs regexps ending with a $ in a Tornado app that was handed to my team... Maybe I'm not the most web literate guy and this is obvious for others, but I don't see the difference it makes to explicitly indicate the end of line when matching the whole string (not searching inside).
Is there something that I'm missing or it is just redundant?
edit to make clearer what I mean:
handlers = [
tornado.web.URLSpec(r'/About/$', ShowSettingsHandler),
...
]
that should be exactly the same as:
handlers = [
tornado.web.URLSpec(r'/About/', ShowSettingsHandler),
...
]
as the handler dispatcher looks for an exact match, not a substring.
There is no need for the trailing
$
in Tornado. I put them in out of habit, and because I think it's clearer, butr"^/hello"
will ONLY match /hello.We can see this by looking at the URLSpec source:
The difference is that the
$
sign ensures that the pattern even if matched fully, is not a substring of another pattern. See these two regexes to match url patterns.with $ sign : http://regexr.com?327d2
without $ sign : http://regexr.com?327d5
And here is some excerpt from the djangobook, which may be relevant to tornado as well :
^hello/$