Issue 35653: All regular expression match groups are the empty string
Created on 2019-01-03 21:29 by adiba, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg332948 - (view) | Author: (adiba) | Date: 2019-01-03 21:29 | |
This is the regular expression: ^(?:(\d*)(\D*))*$
This is the test string: 42AZ
This is the expectation for the match groups: ('42', 'AZ')
This is the actual return value: ('', '')
https://gist.github.com/adiba/791ba943a1102994d43171dc98aaecd0
|
|||
| msg332956 - (view) | Author: Matthew Barnett (mrabarnett) * ![]() |
Date: 2019-01-04 01:13 | |
Look at the spans of the groups:
>>> import re
>>> re.search(r'^(?:(\d*)(\D*))*$', "42AZ").span(1)
(4, 4)
>>> re.search(r'^(?:(\d*)(\D*))*$', "42AZ").span(2)
(4, 4)
They're telling you that the groups are matching twice (because of the outer *). The first time, they match ('42', 'AZ'); the second time, they match ('', '') at the end of the string.
Not a bug.
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:09 | admin | set | github: 79834 |
| 2019-01-05 11:05:10 | adiba | set | nosy:
- ezio.melotti, mrabarnett, adiba |
| 2019-01-04 01:13:35 | mrabarnett | set | status: open -> closed resolution: not a bug messages: + msg332956 stage: resolved |
| 2019-01-03 21:29:10 | adiba | create | |
