0

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

Shubhendu Pramanik
  • 2,711
  • 2
  • 13
  • 23
  • 3
    Possible duplicate of [Does "\d" in regex mean a digit?](https://stackoverflow.com/questions/6479423/does-d-in-regex-mean-a-digit) – itzMEonTV Dec 21 '17 at 12:30
  • [This StackOverflow question](https://stackoverflow.com/questions/42107175/django-url-regex-with-variables) may be helpful for more information on django url patterns – Josh Withee Dec 21 '17 at 12:31

1 Answers1

3

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]

Alasdair
  • 298,606
  • 55
  • 578
  • 516
hansaplast
  • 11,007
  • 2
  • 61
  • 75