Regex is a regular expression extended functionality library to provide centralized and improved functions over RegExp object.
To install the library you need to run npm i regex
or with yarn yarn install regex
from the CLI.
In order to instanciate the class you can do it easily passing the regular expression as a string or as a RegExp object to the class constructor.
import Regex from "regex"
const regex = new Regex("Hello world")
These methods intend to override default String.prototype methods.
This method provides string matching with an improved functionality returning the regular expression matches as an array of strings or null.
const regex = new Regex(/Hello.*/)
console.log(regex.match("Hello world"))
// ["Hello world"]
This method does the same as String.prototype.match() but returning an array of string arrays on regular expressions with g
flag.
const regex = new Regex(/o/g)
console.log(regex.matchAll("Hello world"))
// [["o"], ["o"]]
These methods intend to override default RegExp.prototype methods.
This method test the regular expression against the given string parameter as RegExp.prototype.test() would do.
const regex = new Regex(/Hello (.*)/)
console.log(regex.test("Hello world"))
// true
These methods intend to extend regular expression handling by adding custom functionality.
This method returns an array of strings with regular expression groups.
const regex = new Regex(/(Hello (.*))/)
const groups = regex.groups()
console.log(groups)
// groups[0] = "(Hello (.*))/"
// groups[1] = "(.*)"
This property contains the regular expression passed in the instance constructor as a RegExp objet.
This property displays the regular expression instantiation acceptance.
This property displays whether the regular expression has a g
flag.
As my regular expression knowledge is very limited I ask you for any help you can provide. You are more than welcome to fork this repository or to pull any issues you might observe. In case you wanna contribute in any other way you can reach me by email to [email protected].
This package has been build using TSDX.
This library has MIT license.