这个Django正则表达式是什么意思?`?P` [英] What does this Django regular expression mean? `?P`

查看:64
本文介绍了这个Django正则表达式是什么意思?`?P`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 urls.py 中具有以下正则表达式(regex),我想知道它的含义.特别是正则表达式的(?P< category_slug> 部分.

  r'^ category/(?P< category_slug> [-\ w] +)/$ 

解决方案

(?P< name> regex)-圆括号将正则表达式分组.它们捕获其中正则表达式匹配的文本,这些文本可以用尖括号之间的名称引用.名称可以由字母和数字组成.

从以下位置复制粘贴: http://www.regular-expressions.info/refext.html

I have the following regular expression (regex) in my urls.py and I'd like to know what it means. Specifically the (?P<category_slug> portion of the regex.

r'^category/(?P<category_slug>[-\w]+)/$

解决方案

(?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

这篇关于这个Django正则表达式是什么意思?`?P`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆