Find closest match to a string
Question:
I need to find the closet match to a string. So let’s say a user types in a name of a show. If what they type in is fairly close to a valid show, then we’ll assume that one.
Example:
Valid Input: 24, Prison Break, CSI: NY, …
So now the user wants to get to CSI: NY, so they might type in:
csi new york
csi ny
csi:ny
csi now york – miss-spelling
…
they obviously meant CSI: NY. How can I check the input against valid names and show the one that most matches?
Solution:
Both ‘CSI: NY’ and ‘Prison Break’ match in 5 places, counting the space
To favour matches at the beginning, try
String::Approx::aslice(‘^csi-new york’,["i","minimal_distance"],map”^$_”,split/,\s*/,”24, Prison Break, CSI: NY, …”)













Comments (0)
Trackbacks - Pingbacks (0)
Leave a Reply