My initial guess would've been dynamic programming (levenstein distance), but if this is API-wide, did you make a suffix tree?