Skip to content

Levenshtein Distance ​

The /levenshtein endpoint allows you to calculate the Levenshtein distance between two strings. This distance represents the minimum number of operations required to transform one string into another.

Parameters ​

ParameterRequiredDescription
str1YesThe first string
str2YesThe second string

Request Example ​

GET /v3/levenshtein?str1=example&str2=samples

Response ​

json
{
    "str1": "example",
    "str2": "samples",
    "distance": 3
}

Response Fields ​

FieldDescription
str1The first input string
str2The second input string
distanceThe Levenshtein distance between the two strings

cURL ​

bash
curl -X GET "https://api.sylvain.sh/v3/levenshtein?str1=example&str2=samples"

Error Handling ​

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
Please provide a first string (?str1={string})The str1 parameter is missing
Please provide a second string (&str2={string})The str2 parameter is missing

About Levenshtein Distance ​

The Levenshtein distance is a measure of the similarity between two strings. It counts the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other. This is useful for:

  • Spell checking
  • DNA sequence analysis
  • Fuzzy string matching
  • Plagiarism detection