Skip to content

maramal/regex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Regex

Regex is a regular expression extended functionality library to provide centralized and improved functions over RegExp object.

Installation

To install the library you need to run npm i regex or with yarn yarn install regex from the CLI.

Initialize the class

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")

String methods

These methods intend to override default String.prototype methods.

Regex.Match

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"]

Regex.MatchAll

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"]]

RegExp methods

These methods intend to override default RegExp.prototype methods.

Regex.test

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

Custom functions

These methods intend to extend regular expression handling by adding custom functionality.

Regex.groups

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] = "(.*)"

Properties

Regex.regex: RegExp

This property contains the regular expression passed in the instance constructor as a RegExp objet.

Regex.isValid: boolean

This property displays the regular expression instantiation acceptance.

Regex.isGlobal: boolean

This property displays whether the regular expression has a g flag.

Contribute

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].

Third party libraries

This package has been build using TSDX.

License

This library has MIT license.

About

No description, website, or topics provided.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published