Message372104
| Author |
Yujiri |
| Recipients |
Yujiri, ezio.melotti, mrabarnett |
| Date |
2020年06月22日.17:28:11 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1592846891.21.0.0506467079294.issue41080@roundup.psfhosted.org> |
| In-reply-to |
| Content |
```
>>> re.sub('a*', '-', 'a')
'--'
>>> re.sub('a*', '-', 'aa')
'--'
>>> re.sub('a*', '-', 'aaa')
'--'
```
Shouldn't it be returning one dash, not two, since the greedy quantifier will match all the a's? I understand why substituting on 'b' returns '-a-', but shouldn't this constitute only one match? In Python 2.7, it behaves as I expect:
```
>>> re.sub('a*', '-', 'a')
'-'
>>> re.sub('a*', '-', 'aa')
'-'
>>> re.sub('a*', '-', 'aaa')
'-'
```
The original case that led me to this was trying to normalize a path to end in one slash. I used `re.sub('/*$', '/', path)`, but a nonzero number of slashes came out as two. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2020年06月22日 17:28:11 | Yujiri | set | recipients:
+ Yujiri, ezio.melotti, mrabarnett |
| 2020年06月22日 17:28:11 | Yujiri | set | messageid: <1592846891.21.0.0506467079294.issue41080@roundup.psfhosted.org> |
| 2020年06月22日 17:28:11 | Yujiri | link | issue41080 messages |
| 2020年06月22日 17:28:11 | Yujiri | create |
|