You can generate a regular expression programmatically. I will leave this as an exercise for the reader, but to output this hypothetical function (given the input of a “word”) you want something like this line:
"^(?>word|wodr|wrod|owrd|word.|wor.d|wo.rd|w.ord|.word|wor.?|wo.?d|w.?rd|.?ord)$"
In English, you first try to combine the word with yourself, then on every possible single transposition, then on every possible single insertion, then on every possible single omission or substitution (can be performed simultaneously).
The length of this string given by a word of length n is linear (and especially not exponential) with n.
This is reasonable, I think.
You pass this to the regular expression generator (for example, in Ruby it will be Regexp.new (str)) and bam, you have an assistant for ANY word with a Damerau-Levenshtein distance of 1 from the given word.
(The Damerau-Levenshtein 2 distance is much more difficult.)
Note the use of the construct (?> Non-backtracing, which means the order of the individual expressions in this release.
I could not think of a way to “squeeze” this expression.
EDITOR: I got him a job, at least in Elixir! https://github.com/pmarreck/elixir-snippets/blob/master/damerau_levenshtein_distance_1.exs
I would not recommend this though (except for educational purposes), since it will only lead you to distances of 1; DL's legitimate library will allow you to compute distances> 1. Although, since it is a regular expression, it will probably work pretty quickly after building (note that you should save the “compiled” regular expression somewhere, since this code is currently time restores it with EVERY comparison!)