npm install enregex
| npm i enregex
// ES5
const Enregex = require("enregex")
// ES6
import Enregex from "enregex"
// Or import both 'Enregex' and 'Util'.
const { Enregex, Util } = require("enregex")
import { Enregex, Util } from "enregex"
// Creating an instance of Enregex by many ways:
// - using string:
new Enregex("foo", "igm")
// - using regex:
new Enregex(/bar/yu)
// - using array:
new Enregex(["hello", "world"])
- Enregex.build()
- <Enregex>.prototype
- Util.beacons()
- Util.checkURLs()
- Util.endsWith()
- Util.factorize()
- Util.startsWith()
Builds an Enregex instance with more human-friendly syntax.
Enregex.build("startsWith: 0 or abc or (def \\(ghi\\)); endsWith: 1 or ( smth ); src: (?:not-before(a)b or c not-after(d)) or group<abc>(abc)repeat: (<abc>, 2)", "abuuuismgadfge")
// Enregex /^(?:0|abc|def \(ghi\))(?:(?<!a)b|c(?!d))|(abc)abc{2}(?:1| smth )$/gimsu
Returns an array of strings (Array<string>
) which can be matched by the regex.
new Enregex(/foo(bar)?|bar?/).array
// (4) ["foo", "foobar", "ba", "bar"]
Returns a boolean whether the given argument includes the regex or not.
new Enregex(/foo(bar)?|bar?/).includes(["ba", "foobar"])
// true
new Enregex(/foo(bar)?|bar?/).includes(["bar", "fooba"])
// false
Returns an array of regex (Array<Enregex>
) by the 'alternate' character.
new Enregex(/foo|bar/i).split()
// (2) [/foo/i, /bar/i]
Finds beacons and their content into an array.
Util.beacons("-anchor There is a -tag rain-bow - \\-here. -a -b", { position: "start" })
// (2) [ [ '-anchor', ' There is a' ], [ '-tag', ' rain-bow - \\-here.' ] ]
Returns URLs by given parameters.
Util.checkURLs({ secured: !0, str: "There is a link [https://code.visualstudio.com/api/references/theme-color#peek-view-colors](https://code.visualstudio.com/api/references/theme-color#peek-view-colors)." })
// (1) ['https://code.visualstudio.com/api/references/theme-color#peek-view-colors']
Returns a boolean whether true or false if a string or a line ends with the wanted string with the wanted options or not.
Util.endsWith("foobar", "bAr", { flags: "i" })
// true
Factorizes some calculs in a string.
Util.factorize("2y - z * 2 | (4-z) (x/3 * 4) - (4-z)(1 / xy)")
// "2(y-z) | (4-z)((x/3 * 4)-(1 / xy))"
Returns a boolean whether true or false if a string or a line starts with the wanted string with the wanted options or not.
Util.startsWith("foobar", "fOo", { flags: "i" })
// true