Ezio Melotti <[email protected]> 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 <[email protected]>
<https://bugs.python.org/issue7940>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com