[issue40259] re.Scanner groups

2020-04-12 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Copy paste of the contents in the text file

In the re module there is an experimental feature called Scanner.
Some unexpected behavior was found while working with it.
Here is an example:

>>> re.Scanner([('\w+=(\d+);', lambda s,g: s.match.group(1))]).scan('x=5;')
(['5;'], '')

The obvious error is the semicolon returned via capturing group 1.

Adding a dummy rule at the beginning, seems to solve that issue:

>>> re.Scanner([('z', None), ('\w+=(\d+);', lambda s,g: 
>>> s.match.group(1))]).scan('x=5;')
(['5'], '')

Adding a capturing group around \w+ also returns the correct answer:

>>> re.Scanner([('z', None), ('(\w+)=(\d+);', lambda s,g: 
>>> s.match.group(1))]).scan('x=5;')
(['x'], '')

But then, if I ask for the second group, the problem appears again:

>>> re.Scanner([('z', None), ('(\w+)=(\d+);', lambda s,g: 
>>> s.match.group(2))]).scan('x=5;')
(['5;'], '')

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40259] re.Scanner groups

2020-04-12 Thread Dennis Chronopoulos


Change by Dennis Chronopoulos :


Added file: https://bugs.python.org/file49049/re.Scanner.txt

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40259] re.Scanner groups

2020-04-12 Thread Karthikeyan Singaravelan


New submission from Karthikeyan Singaravelan :

Please add a description of the issue you are facing with a simple script of 
the behavior.

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40259] re.Scanner groups

2020-04-12 Thread Dennis Chronopoulos


Change by Dennis Chronopoulos :


--
components: Regular Expressions
nosy: dchron, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: re.Scanner groups
type: behavior
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com