Issue 32319: re fullmatch error with non greedy modifier (original) (raw)
Consider this code snippet:
from re import match, fullmatch
pattern = '".+?"' string = '"hello" "again"'
print(match(pattern, string)) print(fullmatch(pattern, string))
Which prints: <_sre.SRE_Match object; span=(0, 7), match='"hello"'> <_sre.SRE_Match object; span=(0, 15), match='"hello" "again"'>
The fullmatch function seems to ignore the non-greedy modifier.
From the fullmatch docstring I expected that fullmatch is equivalent to:
def fullmatch(pattern, string): match = re.match(pattern, string) if match: if match.start() == 0 and match.end() == len(string): return match else: return None else: return None