# Regex to match similar strings

**URL:** <https://www.ruby-forum.com/t/regex-to-match-similar-strings/191446>\
**Category:** Ruby\
**Created:** [July 12, 2010, 10:55pm UTC](https://www.ruby-forum.com/t/regex-to-match-similar-strings/191446 "2010-07-12T22:55:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [July 12, 2010, 10:55pm UTC](https://www.ruby-forum.com/t/regex-to-match-similar-strings/191446/1 "2010-07-12T22:55:54Z")

</div>

Hi,

Im writing some validation code the basically make sure a users login is  
not too similar to their password. I was thinking a regular expression  
to match similarities and if they are alike then make the user change  
their password.

This doesnt have to be bullet proof just enough to really say if  
someones username is bobbysmith then their password cant be bobbysmith7  
or bobbysmi7

Anyone got a solution, is it possible to do this with a regular  
expression or will it be some ruby code ina loop…

JB

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [July 12, 2010, 11:06pm UTC](https://www.ruby-forum.com/t/regex-to-match-similar-strings/191446/2 "2010-07-12T23:06:25Z")

</div>

Here are a couple ruby libraries that may help you out. I found this a  
while back on a ruby sitewhen I was looking to compare strings for  
duplicates when cleansing data.  
The first is distance between strings. (I prefer this one)  
The second is the traditional soundex Remove vowels take the first  
letter run a calc on the rest.Its not very reliable but may help.  
The third is like soundex but larger strings.  
[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/)  
Here is the link to the original  
post:[http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/1276ccf14b3d6ca6/3750d67dc7b2f496?lnk=gst&q=double+metaphone&pli=1](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/1276ccf14b3d6ca6/3750d67dc7b2f496?lnk=gst&q=double+metaphone&pli=1)

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [July 13, 2010, 12:32am UTC](https://www.ruby-forum.com/t/regex-to-match-similar-strings/191446/3 "2010-07-13T00:32:55Z")

</div>

Thanks Chris, exactly what i needed. Installed the amatch gem and have  
it running now,

[http://flori.github.com/amatch/doc/Amatch/Levenshtein.html](http://flori.github.com/amatch/doc/Amatch/Levenshtein.html)

JB
