Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:09:14+00:00 2026-05-31T22:09:14+00:00

Id like to compare two strings in Ruby and find their similarity I’ve had

  • 0

Id like to compare two strings in Ruby and find their similarity

I’ve had a look at the Levenshtein gem but it seems this was last updated in 2008 and I can’t find documentation how to use it. With some blogs suggesting its broken

I tried the text gem with Levenshtein but it gives an integer (smaller is better)

Obviously if the two strings are of variable length I run into problems with the Levenshtein Algorithm (Say comparing two names, where one has a middle name and one doesnt).

What would you suggest I do to get a percentage comparison?

Edit: Im looking for something similar to PHP’s similar text

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:09:15+00:00Added an answer on May 31, 2026 at 10:09 pm

    I think your question could do with some clarifications, but here’s something quick and dirty (calculating as percentage of the longer string as per your clarification above):

    def string_difference_percent(a, b)
      longer = [a.size, b.size].max
      same = a.each_char.zip(b.each_char).count { |a,b| a == b }
      (longer - same) / a.size.to_f
    end
    

    I’m still not sure how much sense this percent difference you are looking for makes, but this should get you started at least.

    It’s a bit like Levensthein distance, in that it compares the strings character by character. So if two names differ only by the middle name, they’ll actually be very different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use Oracle's utl_match.edit_distance function. It supposed to compare two strings and
I get two strings formated like (Brazilian Format): DD/MM/YYYY, I need to compare both.
I have two strings Like 0101000000110110000010010011 and 0101XXXXXXX101100000100100XX it should compare each character and
In MySQL, how can I compare two strings and get matching percentage. Something like
I have two arrays of strings that I would like to compare for equality:
Is there a simple way in C# to compare two strings and find out
I would like to compare two strings and get some score how much these
I have two strings which I'd like to compare: String and String: . Is
I would like to compare two dates in javascript. I have been doing some
I would like to compare two tables and then update if some logic is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.