Misfits09 / regex-factorize

Factorize regexes with lists of numbers into more performant factorized Regexes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 regex

    Example : 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)))

About

Factorize regexes with lists of numbers into more performant factorized Regexes

License:GNU General Public License v3.0


Languages

Language:JavaScript 56.4%Language:TypeScript 43.6%