I的一部分有一对串查找接触和非接触的两个字符串
YHFLSPYVY # answer
LSPYVYSPR # prediction
+++******ooo
YHFLSPYVS # answer
VEYHFLSPY # prediction
oo*******++
如上所述以上我想找到重叠区域(*
)和非重叠区域中的答案的两个例子(+
)和预测(o
)。
我该怎么用Python做到这一点?
我坚持这个
import re
# This is of example 1
ans = "YHFLSPYVY"
pred= "LSPYVYSPR"
matches = re.finditer(r'(?=(%s))' % re.escape(pred), ans)
print [m.start(1) for m in matches]
#[]
的答案,我希望能得到例如1:
plus_len = 3
star_len = 6
ooo_len = 3
你想第一重叠?还是最长的重叠? –
你是否也想要带* + o的字符串或只是plus_len等的值? –
看起来像[最长的公共子序列](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem) –