import re
rt = re.search(r'(\d)+(\w+)(\$+)', '123abc$$$')
print(rt.group(1))
结果为啥是 3 呢,正则从左向右匹配,+ 算贪婪,不应该是 1 吗?
1
brucmao OP 用 regex101.com 试了下,明白了,只捕获最后一个迭代
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data |