0

I have to arrays that contain names of premier league players. I want to match them by name since the player objects don't have unique ids.

How can I make a string comparison that will match Zlatan Ibrahimovic with Zlatan Ibrahimović for example? (notice the last character of both strings)

3
  • 3
    Regular expressions are your friend. Commented Sep 26, 2016 at 20:11
  • but therefore I would have to know each representation of one letter in the other name, right? Commented Sep 26, 2016 at 20:19
  • You would have to know that a "c" with an accent mark is "equivalent" to a "c" without one. But there's no way for the computer to know that without you telling it. Commented Sep 26, 2016 at 20:20

1 Answer 1

1

It is not a trivial problem. You should look into Levenshtein distance problem

https://en.wikipedia.org/wiki/Levenshtein_distance

You can search in google for different implementations or use a library like: https://www.npmjs.com/package/levenshtein

Example:

l = new Levenshtein( 'Zlatan Ibrahimovic', 'Zlatan Ibrahimović')
// l === 1

I used already, and I liked. In my code, I used this one for an experimental proposed.

I don;t care about the result. Because in a long string 4 can be a very good number and in small one 2 it is very bad.

I get to do something like l/Math.max(str1.length, str2.length) then you can make your number and decide wich number is interesting for you.

Sign up to request clarification or add additional context in comments.

1 Comment

The Levenshtein distance is used for calculating the minimal number of edits to make two strings equivalent, right? I don't think that's what OP is trying to accomplish. Just using the Levenshtein distance and a threshold of 2, Zlatan and Klatap would match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.