[docs] [issue7940] re.finditer and re.findall should support negative end positions

Ezio Melotti report at bugs.python.org
Mon Jul 15 20:36:45 EDT 2019


Ezio Melotti <ezio.melotti at gmail.com> added the comment:

> Are there any real world examples which show the benefit of supporting 
> negative indices?

A common case is ignoring parentheses at the beginning/end, e.g.
>>> re.compile('[^,]+').findall('(foo,123,(),bar)')
['(foo', '123', '()', 'bar)']
>>> # ignore the surrounding ()
>>> re.compile('[^,]+').findall('(foo,123,(),bar)', 1, 15)
['foo', '123', '()', 'bar']
>>>
>>> # extract attributes from a tag (poc, doesn't handle all cases)
>>> re.compile('[^ ]+').findall('<input type="checkbox" id="foo" checked>', 7, 39)
['type="checkbox"', 'id="foo"', 'checked']

In both cases using -1 as endpos is simpler.

----------
versions: +Python 3.9 -Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue7940>
_______________________________________


More information about the docs mailing list