[issue42448] re.findall have different match result against re.search or re.sub

2021-08-17 Thread Rondevous
Rondevous added the comment: I was frustrated for hours when I couldn't figure out why this won't match: >>> re.findall(r'(foo)?bar|cool', 'cool') Now I know, I have to make this change: (?:foo) But this isn't obvious. Should it be mentioned in the docs of re.findall() to use (?:...) for

[issue42448] re.findall have different match result against re.search or re.sub

2020-11-23 Thread 赵豪杰
赵豪杰 <1292756...@qq.com> added the comment: AhAh, got it, I misunderstood the usage, the findall returns tuple of groups the expression set. Thanks @serhiy.storchaka @rhettinger -- resolution: -> not a bug stage: -> resolved status: open -> closed

[issue42448] re.findall have different match result against re.search or re.sub

2020-11-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: When groups are present in the regex, findall() returns the subgroups rather than the entire match: >>> mo = re.search('(12)+', '121212 and 121212') >>> mo[0] # Entire match '121212' >>> mo[1] # Group

[issue42448] re.findall have different match result against re.search or re.sub

2020-11-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It looks correct to me. Of course, the result is different, because they are different functions. re.match() and re.search() return a match object (or None), and re.findall returns a list. What result did you expect? -- nosy: +serhiy.storchaka

[issue42448] re.findall have different match result against re.search or re.sub

2020-11-23 Thread 赵豪杰
New submission from 赵豪杰 <1292756...@qq.com>: ``` >>> import re >>> text = '121212 and 121212' >>> pattern = '(12)+' >>> print(re.findall(pattern, text)) ['12', '12'] >>> >>> >>> print(re.search(pattern, text)) >>> >>> >>> print(re.sub(pattern, '', text)) and # The re.findall have