Your task, at the moment that you choose to accept it, is to write a program that, when given a string and a PCRE-regex, calculates the minimum Levenshtein distance to another string that matches the regex (fully). All strings, as well as the regexes, should be in the Latin-1 character set.
This is code-golf
, so the shortest program wins.
The Levenshtein distance (or edit distance) between two strings is the closeness of two strings, measured in operations needed to go from one string to another. One operation is one insertion, one deletion, or one substitution.
Examples
a, ab+ -> 1
because ab
matches ab+
and levenshtein(a, ab) = 1
aaa, .* -> 0
because aaa
matches
aaaa, ab+a -> 2
because aba
matches and levenshtein(aaaa, aba) = 2
abcde, a.?b?.?a -> 2
because abca
matches and levenshtein(abcde, abca) = 2