Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Django url正则表达式未匹配_Regex_Django_Django Urls - Fatal编程技术网

Regex Django url正则表达式未匹配

Regex Django url正则表达式未匹配,regex,django,django-urls,Regex,Django,Django Urls,我需要匹配url中的url编码空格,即%20 我的url应该是 http://domain/something/hello%20world 这是我的url配置和视图 url(r'^regtest/(\w+[%20]?\w+)', views.regView) 视图: 这是我在url上点击的日志 http://127.0.0.1:8000/regtest/hello%20world hello and None [13/Jan/2014 02:12:31] "GET /regtest/hel

我需要匹配url中的url编码空格,即%20

我的url应该是

http://domain/something/hello%20world
这是我的url配置和视图

url(r'^regtest/(\w+[%20]?\w+)', views.regView)
视图:

这是我在url上点击的日志

http://127.0.0.1:8000/regtest/hello%20world

hello and None
[13/Jan/2014 02:12:31] "GET /regtest/hello%20world HTTP/1.1" 200 3

模式
[%20]
匹配
%
2
0

改为使用以下正则表达式来匹配单词字符(
\w
)或(
|
),
%20

r'^regtest/((?:\w|%20)+)'

更新

%20
由Django解释并解码为空格(
)。因此,您应该匹配空格,而不是
%20

r'^regtest/([\w\s]+)'

当我在url配置中使用它时,它甚至没有得到匹配。我对它进行了交叉检查,我也尝试了以下常规表达式。(\w+(%20)?\w+)
>>> import re
>>> matched = re.search(r'regtest/((?:\w|%20)+)', 'regtest/hello%20world')
>>> matched.group(1)
'hello%20world'
r'^regtest/([\w\s]+)'