Stop being the product.
Become the owner.
or
sign uplog in

TreRegex provides a high-performance Node interface to the…

TreRegex provides a high-performance Node interface to the TRE C library. It brings robust approximate regular expression matching to JS, featuring multi-byte Unicode string safety, and granular error limits

`@tre-regex/regex` provide interface to TRE regex lib. What use cases? Standard regular expressions are strictly exact. If you are searching text containing typos, OCR errors, or variations in spelling, standard `Regexp` will fail (like OCR made mistake and recognize on image 0 as O or | as 1).`@tre-regex/regex` solves this by allowing you to search for a pattern within a larger body of text while permitting a configurable number of errors (insertions, deletions, and substitutions). Example:

const regex = new TreRegex('banana')

// Allow up to 2 typos of any kind
regex.exec('bananana', { maxErrors: 2 }) // => matches "bananana" (2 insertions)
regex.exec('bnnna', { maxErrors: 2 }) // => matches "bnnna" (2 deletions)
regex.exec('bonono', { maxErrors: 2 }) // => matches "bonono" (2 substitutions)

// Another example
const strictRegex = new TreRegex('library')

// Allow 1 deletion, but STRICTLY 0 substitutions and 0 insertions
strictRegex.exec('librry', { maxDeletions: 1, maxSubstitutions: 0, maxInsertions: 0 })
// => matches "librry"

// This fails because 'lubrary' requires a substitution, which we set to 0
strictRegex.exec('lubrary', { maxDeletions: 1, maxSubstitutions: 0, maxInsertions: 0 })
// => undefined

// Another example
const regex = new TreRegex('algorithm')

// We allow a maximum cost of 2.
// Missing/extra characters cost 1 point.
// Wrong characters cost 3 points.
const options = {
maxCost: 2,
weightDeletion: 1,
weightInsertion: 1,
weightSubstitution: 3,
}

// 'algoritm' has 1 deletion. Cost = 1. (Passes, 1 < 2)
regex.test('algoritm', options) // => true

// 'algorethm' has 1 substitution. Cost = 3. (Fails, 3 > 2)
regex.test('algorethm', options) // => false

#programming #technology #js #dev
earnings
4,000 mlx total
$0  total
engagement
5 views
0 reactions

0 comments