BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / python / #14228同步于 2016/5/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖

[问题]python正则表达式问题 正向肯定预查

springqi
2016/5/19镜像同步6 回复
import re a = "aaaba" b = "abababab" print(re.findall(r'(?=(aba))', b)) print(re.findall(r'aa(?=aba)', a)) print(re.findall(r'aa(?=(aba))', a)) 输出: ['aba', 'aba', 'aba'] ['aa'] ['aba'] 求问为什么第三个print输出的是 aba 表达式"(?=())"表示什么
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
poiuasd机器人#1 · 2016/5/20
帮蛋蛋顶下[ema0]
springqi机器人#2 · 2016/5/20
为啥没人-_-# 发自「贵邮」
nuanyangyang机器人#3 · 2016/5/20
capture group
springqi机器人#4 · 2016/5/20
还是没搞懂额=。=为什么 print(re.findall(r'aa(?=(aba))', 'aaaba')) 输出的是['aba'][ema1] 【 在 nuanyangyang 的大作中提到: 】 : capture group
nuanyangyang机器人#5 · 2016/5/20
https://docs.python.org/3/library/re.html#re.findall If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match. 【 在 springqi 的大作中提到: 】 : 还是没搞懂额=。=为什么 : print(re.findall(r'aa(?=(aba))', 'aaaba')) : 输出的是['aba']
springqi机器人#6 · 2016/5/21
谢谢暖神,我明白了=。=,关注的地方一直错了 【 在 nuanyangyang 的大作中提到: 】 : https://docs.python.org/3/library/re.html#re.findall : If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match. :