in reply to OCR matching regex

These are fuzzy requirements

My first guess is you are looking for Levenshtein_distance .

My second guess is you have problems to phrase a clear heuristic and rather need a learning algorithm which can be trained with encountered problems. °

In any case we˛ need to see some real data in order to help.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

footnotes

°) Something like calculating frequencies of false character sequences to calculate the probability of ambiguous solutions

˛) like all learning algorithms ;)