Levenshtein distance

Count the single-character edits needed to turn one string into another, with a similarity ratio.

Input

The first string.
The second string.
Treat upper and lower case as different.

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/levenshtein \
  -H 'Content-Type: application/json' \
  -d '{"input":{"a":"kitten","b":"sitting"}}'
import json, urllib.request

body = {'input': {'a': 'kitten', 'b': 'sitting'}}
request = urllib.request.Request("https://setget.net/v1/tools/levenshtein", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/levenshtein", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"a":"kitten","b":"sitting"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "levenshtein",
  "input": {
    "a": "kitten",
    "b": "sitting"
  }
}
{
  "input": {
    "a": "kitten",
    "b": "sitting"
  }
}

Endpoint: POST /v1/tools/levenshtein. Over MCP: run_tool with slug: "levenshtein". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
a string yes The first string.
b string yes The second string.
case_sensitive boolean no Treat upper and lower case as different. Default: true.

Examples

Input
{
  "a": "kitten",
  "b": "sitting"
}
Result
{
  "distance": 3,
  "similarity": 0.5714,
  "length_a": 6,
  "length_b": 7
}

Ignoring case

Input
{
  "a": "Color",
  "b": "colour",
  "case_sensitive": false
}
Result
{
  "distance": 1,
  "similarity": 0.8333,
  "length_a": 5,
  "length_b": 6
}

Questions

How is similarity calculated?
It is 1 minus the distance divided by the length of the longer string, so 1 means identical and 0 means nothing in common.
What counts as one edit?
Inserting, deleting or replacing a single character. Swapping two neighbouring characters counts as two edits.