知识卡片
选择分支按尝试顺序匹配
正则的|依顺序尝试分支,第一个可成功的分支可能遮蔽后面更长的分支。H|Hobson可只取H,顺序会影响结果;findall另按输入位置找非重叠匹配,不按分支列表顺序重排文本。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
The | symbol is used to separate strings that can alternatively match the input string to produce an overall match for the regular expression. So the regular expression 'Hobson|Cole|Hannes' would match any of the first names of the authors of the first edition of this book. Patterns are processed left to right and “short circuit” when a match is made, like most other programming languages.
参考来源
- 位置:《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)
- 结论依据:摘录中关于选择分支按尝试顺序匹配的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。
- 原始内容:The | symbol is used to separate strings that can alternatively match the input string to produce an overall match for the regular expression. So the regular expression 'Hobson|Cole|Hannes' would match any of the first names of the authors of the first edition of this book. Patterns are processed left to right and “short circuit” when a match is made, like most other programming languages.