selfteaching / selfteaching/selfteaching-python-camp

【自学内容】 关于正则表达式 (er)+ 的疑惑

Open
#3,615 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
151
Forks
875
PR merge metrics
No merged PRs in 30d

Description

《自学是门手艺》正则表达式部分有这样一段代码:
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

import re

str = 'error wonderer severeness'

pttn = r'(er)+'
re.findall(pttn, str)

运行结果是:
['er', 'er', 'er']
这点我不理解,(er)+中的+表示一个或多个,那 wonderer 这个单词中的 erer 就应该被匹配出来啊,为什么结果不是 ['er', 'erer', 'er']?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file is named; start by running the shown Python snippet with re.findall and inspect how the (er)+ pattern is matched in the string. Done means clarifying the explanation so the expected result for “wonderer” is unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.