Levenshtein distance
Count the single-character edits needed to turn one string into another, with a similarity ratio.
Input
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
| Name | Type | Required | What 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.
Related tools
- Fuzzy matchFind the candidates that are most similar to a query, ranked with a score from 0 to 1.
fuzzy-match - Text diffCompare two texts line by line and get a unified diff with counts of added and removed lines.
diff - Apply a patchApply a unified diff to a text and get the patched result, with clear errors when a hunk does not fit.
patch-apply - Case converterConvert text between lower, UPPER, Title, Sentence, camelCase, PascalCase, snake_case, kebab-case and more.
case-convert - Escape and unescape textEscape or unescape text for HTML, URLs, JSON strings, shell commands, regular expressions and CSV fields.
escape-unescape - Extract emails and URLsPull every email address and web link out of a text, and optionally IPv4 addresses and hashtags.
extract-emails-urls