在我的字符串中(从这个turorial中采用的例子)我希望获得所有内容,直到.通用(year).模式之后的第一个:
str = 'purple alice@google.com, (2002).blah monkey. (1991).@abc.com blah dishwasher'
Run Code Online (Sandbox Code Playgroud)
我想我的代码几乎就在那里但尚未完成:
test = re.findall(r'[\(\d\d\d\d\).-]+([^.]*)', str)
Run Code Online (Sandbox Code Playgroud)
...返回: ['com, (2002)', 'blah monkey', ' (1991)', '@abc', 'com blah dishwasher']
所需的输出是:
['blah monkey', '@abc']
换句话说,我想找到年份模式和下一个点之间的所有内容.
如果你想要(year).在第一个和第一个之间获得所有东西,.你可以使用它:
\(\d{4}\)\.([^.]*)
Run Code Online (Sandbox Code Playgroud)
并在此解释:
"\(\d{4}\)\.([^.]*)"g
\( matches the character ( literally
\d{4} match a digit [0-9]
Quantifier: {4} Exactly 4 times
\) matches the character ) literally
\. matches the character . literally
1st Capturing group ([^.]*)
[^.]* match a single character not present in the list below
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
. the literal character .
g modifier: global. All matches (don't return on first match)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
68 次 |
| 最近记录: |