SimilarSubstring is a library that helps you to search for the most similar pattern from the text/paragraph you provided.
This library is implemented based on Evolutionary Distance algorithm written by Sellers, Peter H. It is similar to Levenshtein Distance algorithm, but it is optimized for searching a similar part of the sequence.
- Search for the most similar part of the string by the given pattern
- Return all of the parts if there is more than one most part which is scored the highest mark in terms of similarity
Install using NPM
npm install similar-substring --save
Import to your code
import { similarSubstring } from 'similar-substring';
import { similarSubstring } from 'similar-substring';
// Your code here
const result = similarSubstring("I am coding", "mod");
{
similarity: 0.6666666666666666,
items: [
{ substring: 'od', range: { startIndex: 6, endIndex: 7 } },
{ substring: 'cod', range: { startIndex: 5, endIndex: 7 } }
]
}