← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6801.c · 生成模型:GPT-6

完整匹配和捕获组编号不同

理解等级:中级

group(0)是整个匹配,group(1)起才是左括号计数的捕获。嵌套分组仍按左括号顺序编号,本例((kitt|dogg)(y))的第2组是dogg而第3组是y;不能照抄书中错位输出。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      Groups have another purpose: they can be used to capture (extract) part of the input text. Each group is assigned a location in the list of groups() that you can retrieve according to their index, left to right. The .group() method returns the default overall group for the entire expression. You can use the previous groups to capture a stem (the part without the y)

    参考来源

    - 位置:《Natural Language Processing in Action, Second Edition》附录B《附录B:Python与正则表达式》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Natural Language Processing in Action, Second Edition/_epub-src/OEBPS/Text/appendix-b.html) - 结论依据:摘录中关于完整匹配和捕获组编号不同的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:Groups have another purpose: they can be used to capture (extract) part of the input text. Each group is assigned a location in the list of groups() that you can retrieve according to their index, left to right. The .group() method returns the default overall group for the entire expression. You can use the previous groups to capture a stem (the part without the y)