64
(?P<name>regex)
β Round brackets group the regex between them. They capture the text matched by the regex inside them that can be referenced by the name between the sharp brackets. The name may consist of letters and digits.
Copy paste from: http://www.regular-expressions.info/refext.html
91
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 the rest of the regular
expression via the symbolic group name name. Group names must be valid
Python identifiers, and each group name must be defined only once
within a regular expression. A symbolic group is also a numbered
group, just as if the group were not named. So the group named id in
the example below can also be referenced as the numbered group 1.
- [Django]-Using django-admin on windows powershell
- [Django]-Django: Grab a set of objects from ID list (and sort by timestamp)
- [Django]-Django: multiple models in one template using forms
26
(?P<category_slug>)
creates a match group named category_slug
.
The regex itself matches a string starting with category/
and then a mix of alphanumeric characters, the dash -
and the underscore _
, followed by a trailing slash.
Example URLs accepted by the regex:
- category/foo/
- category/foo_bar-baz/
- category/12345/
- category/q1e2_asdf/
- [Django]-How to configure where to redirect after a log out in Django?
- [Django]-How to compare two JSON objects with the same elements in a different order equal?
- [Django]-Django @login_required decorator for a superuser
-2
New in version 3.6.
(?P<name>...)
Similar to regular parentheses, but the substring matched by the group is accessible via the symbolic group name name. Group names must be valid Python identifiers, and each group name must be defined only once within a regular expression. A symbolic group is also a numbered group, just as if the group were not named.
copy paste from Python3Regex
- [Django]-Django migration strategy for renaming a model and relationship fields
- [Django]-How do I filter ForeignKey choices in a Django ModelForm?
- [Django]-How does Django's nested Meta class work?
-2
In pattern matching,
Use this pattern for passing string
(?P<username2>[-\w]+)
This for interger value
(?P<user_id>[0-9]+)
- [Django]-Django admin, hide a model
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
- [Django]-POST jQuery array to Django