# Re: Detecting similar strings

**URL:** <https://www.ruby-forum.com/t/re-detecting-similar-strings/100824>\
**Category:** Ruby\
**Created:** [August 1, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/re-detecting-similar-strings/100824 "2006-08-01T12:08:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kivle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kivle](https://www.ruby-forum.com/u/kivle)\
**Post date:** [August 1, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/re-detecting-similar-strings/100824/1 "2006-08-01T12:08:54Z")

</div>

This should point you in the right direction I think:

[http://raa.ruby-lang.org/project/levenshtein/](http://raa.ruby-lang.org/project/levenshtein/)  
[http://raa.ruby-lang.org/project/soundex/](http://raa.ruby-lang.org/project/soundex/)  
[http://raa.ruby-lang.org/project/metaphone/](http://raa.ruby-lang.org/project/metaphone/)

The levenshtein algorithm basically gives you the “edit-distance”  
between two strings. E.g. the minimum amount of  
insertions/replacements/deletions to make the strings identical. It  
gives you a pretty good indication on how similar the strings are.

Soundex transforms all strings that are similar into the same 4  
character code (which looks something like “E246”).

Metaphone is preferred over soundex I believe. It also transforms  
similar strings into the same character sequence, but doesn’t limit  
itself to just 4 characters. That means it works a bit better with  
longer strings.

There are probably other algorithms around as well, but I’ve had pretty  
good luck with these three.

Regards,  
Helge E.
