简体   繁体   English

re.findall()返回的元组中的第一个字符串将始终是最长的匹配字符串吗?

[英]Will the first string in a tuple returned by re.findall() always be the longest matching string?

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.')

gives me 给我

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

In this example, the first string of each tuple is the longest. 在此示例中,每个元组的第一个字符串是最长的。 Will that always be the case? 会一直这样吗? If someone knows where the other strings in each tuple are coming from, I would love to know that too! 如果有人知道每个元组中其他字符串的来源,我也很想知道! Thanks! 谢谢!

Will that always be the case? 会一直这样吗?

No, that is never the case. 不,从来没有。 Matches are returned from left to right . 比赛从左到右返回。

re.findall

The string is scanned left-to-right, and matches are returned in the order found 从左到右扫描字符串,并以找到的顺序返回匹配项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM