鱼C论坛

 找回密码
 立即注册
查看: 1382|回复: 2

[已解决]请前辈指点 正则表达式-命名组的问题

[复制链接]
发表于 2018-1-13 22:57:22 | 显示全部楼层 |阅读模式
10鱼币
本帖最后由 wow7jiao 于 2018-1-13 22:59 编辑

http://bbs.fishc.com/thread-57317-1-1.html

这里为什么索引0也可以,1也可以((r'(?P<word>\b\w+\b)') 里面没有小括号)
最佳答案
2018-1-13 22:57:23
  1. >>> m.groups()
  2. ('Lots',)
复制代码


我理解group(0)是匹配到的所有分组
group(1)是匹配到的第一个结果


  1. Help on built-in function group:

  2. group(...) method of _sre.SRE_Match instance
  3.     group([group1, ...]) -> str or tuple.
  4.     Return subgroup(s) of the match by indices or names.
  5.     For 0 returns the entire match.
复制代码
QQ截图20180113225055.png
火狐截图_2018-01-13T14-57-14.607Z.png

最佳答案

查看完整内容

我理解group(0)是匹配到的所有分组 group(1)是匹配到的第一个结果
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-1-13 22:57:23 | 显示全部楼层    本楼为最佳答案   
  1. >>> m.groups()
  2. ('Lots',)
复制代码


我理解group(0)是匹配到的所有分组
group(1)是匹配到的第一个结果


  1. Help on built-in function group:

  2. group(...) method of _sre.SRE_Match instance
  3.     group([group1, ...]) -> str or tuple.
  4.     Return subgroup(s) of the match by indices or names.
  5.     For 0 returns the entire match.
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-1-13 23:29:06 | 显示全部楼层
sky 发表于 2018-1-13 22:57
我理解group(0)是匹配到的所有分组
group(1)是匹配到的第一个结果

感谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 16:22

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表