Jeref Nakop
Jeref Nakop

Reputation: 1

Django regex in url patterns

Is there any difference to use [0-9]+ vs d+ in django url patterns? Any security difference?

Upvotes: 0

Views: 435

Answers (1)

hansaplast
hansaplast

Reputation: 11593

Django uses pythons re module, and from its documentation:

\d [...] Matches any Unicode decimal digit (that is, any character in Unicode character category [Nd]). This includes [0-9], and also many other digit characters. If the ASCII flag is used only [0-9] is matched (but the flag affects the entire regular expression, so in such cases using an explicit [0-9] may be a better choice).

That is, this would also match e.g. arabic numbers. If you want that, then use \d, if not, then use [0-9]

Upvotes: 3

Related Questions