Licence
GPL-3.0
Version
1.0.1
Deps
0
Size
40 kB
Vulns
0
Weekly
0
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-factorize
or with yarn
yarn add regex-factorize
Importation
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)))