classification
Title: _sre.SRE_Scanner object should have a fullmatch() method
Type: enhancement Stage:
Components: Regular Expressions Versions: Python 3.4, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Gareth.Gouldstone, ezio.melotti, mrabarnett, r.david.murray, twouters
Priority: normal Keywords:

Created on 2014-03-21 01:31 by Gareth.Gouldstone, last changed 2014-03-21 08:54 by Gareth.Gouldstone.

Messages (4)
msg214317 - (view) Author: Gareth Gouldstone (Gareth.Gouldstone) Date: 2014-03-21 01:31
I believe that the SRE_Scanner object should have a .fullmatch() method for consistency with other re pattern-matching behaviour.

>>> rex = re.compile('([^\\W\\d_]{1,2}[0-9]{1,2}[^\\d\\W_]?)[ \\t]*([0-9][^\\d\\W_]{2})')
>>> rex.scanner('bn20bs')
<_sre.SRE_Scanner object at 0x102006400>
>>> rex.scanner('bn20bs').search()                                           
<_sre.SRE_Match object; span=(0, 6), match='bn20bs'>
>>> rex.scanner('bn20bs').match()                                           
<_sre.SRE_Match object; span=(0, 6), match='bn20bs'>
>>> rex.scanner('bn20bs').fullmatch()                                           Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: '_sre.SRE_Scanner' object has no attribute 'fullmatch'
msg214320 - (view) Author: Gareth Gouldstone (Gareth.Gouldstone) Date: 2014-03-21 01:45
I also encountered issue 20998, which explains the convoluted [^\W\d_] in place of [a-zA-Z] as I was investigating why case-insensitivity and quantifiers would not work together.
msg214323 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-21 03:09
Scanner isn't a public interface, so the real enhancement here would be to make it one, in which case adding fullmatch would make sense.  I don't know if making it public is a good idea or not.
msg214337 - (view) Author: Gareth Gouldstone (Gareth.Gouldstone) Date: 2014-03-21 08:54
Scanner may not be a public interface but it is widely documented, not least on page 67 of the O'reilly Python Cookbook.

Even if Scanner is not made public, then surely it should maintain consistency with the public interfaces?
History
Date User Action Args
2014-03-21 08:54:46Gareth.Gouldstonesetmessages: + msg214337
versions: + Python 3.4
2014-03-21 03:09:03r.david.murraysetversions: + Python 3.5, - Python 3.4
nosy: + r.david.murray, twouters

messages: + msg214323

type: behavior -> enhancement
2014-03-21 01:45:26Gareth.Gouldstonesetmessages: + msg214320
2014-03-21 01:31:17Gareth.Gouldstonecreate