1.0.1 • Published 3 years ago
regex-factorize v1.0.1
Regex factorization of numbers
Factorize regexes with lists of numbers into more performant factorized Regexes
Installation
Install with one of the following command :
npm install regex-factorizeor with yarn
yarn add regex-factorizeImportation
Then you have access to two methods that can be imported with :
import { regexFromNumberArray, simplifyExistingRegex } from "regex-factorize";or
const {
regexFromNumberArray,
simplifyExistingRegex,
} = require("regex-factorize");Usage
regexFromNumberArray(array): Takes into argument an array of numbers and outputs an optimized regexExample :
regexFromNumberArray([123,124,125,5678,5689])gives :1(2([3-5]))|5(6(78|89))simplifyExistingRegex(string): Takes into argument an existing regex and simplify segments with only digits in a OR.Example 1:
regexFromNumberArray("123|124|125|5678|5689")gives :1(2([3-5]))|5(6(78|89))Example 2:
regexFromNumberArray("a(123|124|125|5678|5689)")gives :a(1(2([3-5]))|5(6(78|89)))