我一直被这个正则表达式所困扰
# Find the following keywords: sea, sear, search,
# Find all overlapping keywords
p = re.compile(r'(sea)+(r?((ch)?))')
pos = 0
while pos<len(s):
m = p.search(s,pos)
if m:
pos = m.end()
w = m.group()
g = m.groups()
#print w,g
for k in range(len(g)):
if g[k]:
w += ', '+g[k]
print w
else:
break
s ='search for searing remarks that mark whether the ark came by sea'
我也需要找到所有重叠的关键字。但是我的尝试产生了
search, sea
search, sea, rch
search, sea, rch, ch
sear, sea
sear, sea, r
sea, sea
我应该如何处理它。我今天才学的。提前致谢
预期结果:sea,sear, search for first 'search' searing 应该产生 sear, sea