简体   繁体   English

了解python中的正则表达式

[英]understanding the regular expression in python

I am learning re in python. 我正在用python学习。
I understand all other things in the following example. 我在以下示例中了解所有其他内容。
but, i really dont understand what special (in tags) means in the following example. 但是,在以下示例中,我真的不理解特殊(在标签中)的含义。

re.compile('((?P<special>[0:-])\s)')

kindly help if know it. 如果知道的话,请帮忙。

They're called named capturing groups. 它们被称为命名捕获组。

A quick explanation here : 这里的简要说明:

Python's regex module was the first to offer a solution: named capture. Python的regex模块是第一个提供解决方案的模块:名为capture。 By assigning a name to a capturing group, you can easily reference it by name. 通过为捕获组分配名称,您可以轻松按名称引用它。 (?P<name>group) captures the match of group into the backreference "name". (?P <name> group)将组的匹配捕获到后向引用“名称”中。 You can reference the contents of the group with the numbered backreference \\1 or the named backreference (?P=name). 您可以使用编号的反向引用\\ 1或命名的反向引用(?P = name)来引用组的内容。

这称为命名捕获组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM