正则表达式
Regular expressions (or regexes ) are a compact way of specifying patterns in text. While Django URLconfs allow arbitrary regexes for powerful URL-matching capability, youll probably use only a few regex patterns in practice. Heres a small selection of common patterns:
正则表达式 (或 regexes ) 是通用的文本模式匹配的方法。Django URLconfs 允许你 使用任意的正则表达式来做强有力的URL映射,不过通常你实际上可能只需要使用很少的一 部分功能。下面就是一些常用通用模式:
Symbol | Matches |
---|---|
. (dot) | Any character |
\d | Any digit |
[A-Z] | Any character, A-Z (uppercase) |
[a-z] | Any character, a-z (lowercase) |
[A-Za-z] | Any character, a-z (case insensitive) |
+ | One or more of the previous expression (e.g., \d+ matches one or more digit) |
[^/]+ | All characters except forward slash |
? | Zero or more of the previous expression (e.g., \d* matches zero or more digits) |
{1,3} | Between one and three (inclusive) of the previous expression |
符号 | 匹配 |
---|---|
. (dot) | 任意字符 |
\d | 任意数字 |
[A-Z] | 任意字符, A-Z (大写) |
[a-z] | 任意字符, a-z (小写) |
[A-Za-z] | 任意字符, a-z (不区分大小写) |
+ | 匹配一个或更多 (例如, \d+ 匹配一个或 多个数字字符) |
[^/]+ | 不是/的任意字符 |
* | 匹配0个或更多 (例如, \d* 匹配0个 或更多数字字符) |
{1,3} | 匹配1个到3个(包含) |
For more on regular expressions, see http://www.djangoproject.com/r/python/re-module/.
有关正则表达式的更多内容,请访问 http://www.djangoproject.com/r/python/re-module/.