更新时间:2023-02-21 15:56:02
Regex 在这里不是合适的工具,我建议:
Regex are not the proper tool here, I would recommend:
代码:
def find(str, ch):
for i, ltr in enumerate(str):
if ltr == ch:
yield i
s = "axaybzb"
startChar = 'a'
endChar = 'b'
startCharList = list(find(s,startChar))
endCharList = list(find(s,endChar))
output = []
for u in startCharList:
for v in endCharList:
if u <= v:
output.append(s[u:v+1])
print(output)
输出:
$ python substring.py
['axayb', 'axaybzb', 'ayb', 'aybzb']