Seems I was over complicating the problem with the previous solution. This is about 50% quicker (23 secs on 15k strings) than the previous one and pretty simple.
rm(list=ls(all=TRUE))
a="xxxappleyyyyyyy"
b="zapllezzz"
s=proc.time()
matchLen=1
matchIndex=1
indexA = 1
repeat {
i = 0
repeat {
srch = substring(a,indexA,indexA+matchLen+i)
if (agrepl(srch,b,max.distance=list(insertions=0,deletions=0,substitutions=1)))
i = i + 1
else {
if (i > 0) {
matchLen = matchLen + i - 1
matchIndex = indexA
}
break
}
}
indexA=indexA+1
if (indexA + matchLen > nchar(a)) break
}
c(matchIndex, matchLen + matchIndex)
print (substring(a,matchIndex, matchLen + matchIndex))
print(proc.time()-s)
This will never be a contender due to the language, but I did have a bit of fun doing it.
Not sure of the complexity of it, but over a couple of ~15k strings it takes 43 secs using a single thread. The largest portion of that was the sorting of the arrays. I tried some other libraries, but without significant improvement.