You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
re.Scanner uses groups internally. You should not refer to groups by number unless you know exactly how re.Scanner works internally. Use named groups instead.
It could be a documentation issue, but re.Scanner is not officially documented, so nothing to do here.
My suggestion to use named groups was incorrect -- no capturing groups are supported in re.Scanner(). Even named group change numbering of groups and mess with capturing groups used by re.Scanner() itself.
Activity
tirkarthi commentedon Apr 12, 2020
Please add a description of the issue you are facing with a simple script of the behavior.
tirkarthi commentedon Apr 12, 2020
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:
The obvious error is the semicolon returned via capturing group 1.
Adding a dummy rule at the beginning, seems to solve that issue:
Adding a capturing group around \w+ also returns the correct answer:
But then, if I ask for the second group, the problem appears again:
serhiy-storchaka commentedon Apr 18, 2022
re.Scanneruses groups internally. You should not refer to groups by number unless you know exactly howre.Scannerworks internally. Use named groups instead.It could be a documentation issue, but
re.Scanneris not officially documented, so nothing to do here.serhiy-storchaka commentedon Oct 31, 2025
My suggestion to use named groups was incorrect -- no capturing groups are supported in
re.Scanner(). Even named group change numbering of groups and mess with capturing groups used byre.Scanner()itself.