New submission from Daniel Hrisca <daniel.hri...@gmail.com>:

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

----------
components: Library (Lib)
messages: 308278
nosy: danielhrisca
priority: normal
severity: normal
status: open
title: re fullmatch error with non greedy modifier
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32319>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to