0
我需要查找字符串中包含相同1個字母的可變長度字符序列的開始和結束位置。 我看到這個主題Finding multiple occurrences of a string within a string in Python,但我認爲它有點關閉。在一個字符串中多次出現1個連續字符串的Python正則表達式
以下給我什麼,而我期望找到5個元素。
import re
s = 'aaaaabaaaabaaabaaba'
pattern = '(a)\1+'
for el in re.finditer(pattern, s):
print 'str found', el.start(), el.end()
在此先感謝。
[它運作良好,只是用**原始字符串字面**](https://開頭ideone。 COM/SxWJdh)。你只能期待4個結果。否則,用'*'替換'+'。 –
WiktorStribiżew,謝謝,尤其是關於*的小費。 – psb