【发布时间】:2013-01-19 11:40:22
【问题描述】:
我在我的代码中使用了 python 正则表达式(re 模块)并注意到这些情况下的不同行为:
re.findall(r'\s*(?:[a-z]\))?[^.)]+', 'a) xyz. b) abc.') # non-capturing group
# results in ['a) xyz', ' b) abc']
和
re.findall(r'\s*(?<=[a-z]\))?[^.)]+', 'a) xyz. b) abc.') # lookbehind
# results in ['a', ' xyz', ' b', ' abc']
我需要得到的只是['xyz', 'abc']。为什么这些示例的行为不同以及如何获得预期的结果?
【问题讨论】:
标签: python regex lookbehind capturing-group