re.findall()返回的元组中的第一个字符串是否总是最长的匹配字符串?

时间:2016-11-27 22:52:39

标签: python regex

re.findall(r'((([0-9]|[a-z]|[A-Z]){5,8}, )*([0-9]|[a-z]|[A-Z]){5,8} reporting and syncing)', 'johnny, joda89 reporting and syncing heyff, jkojo, jkjkjdf, 2378a reporting and syncing and a lot of other jazz. I looked into whether 34987, 22187, and 36547 will report, but no one has gotten back with me about that. Also 34298 reporting and syncing.')

给了我

[('johnny, joda89 reporting and syncing', 'johnny, ', 'y', '9'), ('heyff, jkojo, jkjkjdf, 2378a reporting and syncing', 'jkjkjdf, ', 'f', 'a'), ('34298 reporting and syncing', '', '', '8')]

在此示例中,每个元组的第一个字符串是最长的。总是这样吗?如果有人知道每个元组中的其他字符串来自哪里,我也很想知道它!谢谢!

1 个答案:

答案 0 :(得分:1)

  

总会如此吗?

不,从来没有这样。匹配从从左向右返回

re.findall

  

从左到右扫描字符串,并在中返回匹配项   找到订单