This is fairly complicated and I cannot say I follow all of it. But perhaps LongestSubsequence
would be useful for the task at hand. It is not difficult to determine from the result whether a "near" match occurred, based on whatever criteria you choose for nearness. You'd want to partition the ling sequences so that you are testing pieces of length equal to (or a bit more, if you allow inserts) the primer.