What does this Django regular expression mean? `?P`

In django, named capturing groups are passed to your view as keyword arguments. Unnamed capturing groups (just a parenthesis) are passed to your view as arguments. The ?P is a named capturing group, as opposed to an unnamed capturing group. http://docs.python.org/library/re.html (?P<name>…) Similar to regular parentheses, but the substring matched by the group is accessible within … Read more

Regex optional capturing group?

The reason that you do not get an optional cat after a reluctantly-qualified .+? is that it is both optional and non-anchored: the engine is not forced to make that match, because it can legally treat the cat as the “tail” of the .+? sequence. If you anchor the cat at the end of the … Read more