返回信息流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 表达式"(?=())"表示什么
这是一条镜像帖。来源:北邮人论坛 / python / #14228同步于 2016/5/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
[问题]python正则表达式问题 正向肯定预查
springqi
2016/5/19镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
还是没搞懂额=。=为什么
print(re.findall(r'aa(?=(aba))', 'aaaba'))
输出的是['aba'][ema1]
【 在 nuanyangyang 的大作中提到: 】
: capture group
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']
谢谢暖神,我明白了=。=,关注的地方一直错了
【 在 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.
: