rechain
Regex Chain - A new method for regular expressions.
Installation
npm i rechain --save
Usage
var r = ; var ipv4 = ipv4 = ipv4; console; // (?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}console; // trueconsole; // trueconsole; // [ '192.68.1.1', '8.8.8.8' ]console; // true // check urlvar tlds = 'com|cn';var protocol = '(?:(?:(?:\\w)+:)?\/\/)?';var auth = '(?:\\S+(?::\\S*)?@)?';var host = '(?:xn--[a-z0-9\\-]{1,59}|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?){0,62}[a-z\\u00a1-\\uffff0-9]{1,63}))';var domain = '(?:\\.(?:xn--[a-z0-9\\-]{1,59}|(?:[a-z\\u00a1-\\uffff0-9]+-?){0,62}[a-z\\u00a1-\\uffff0-9]{1,63}))*';var tld = '(?:\\.(?:xn--[a-z0-9\\-]{1,59}|' + tlds + '+))';var port = '(?::\\d{2,5})?';var path = '(?:\/[^\\s]*)?'; var url = var url = console; // true
API
<...>[{m,n}]
.a(re, [m, n]) - - @param{ Mixed } regex string or rechain object
- @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
- @param{ Number } {m,n} <- n, n >= m
var r = ;console; // \dconsole; // trueconsole; // true
<|...>[{m,n}]
.or([re, [m, n]]) - - @param{ Mixed } regex string or rechain object
- @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
- @param{ Number } {m,n} <- n, n >= m
var r = ;console; // hello|worldconsole; // [ 'hello' ]console; // [ 'world' ]
<[...]>[{m,n}]
.m([re, [m, n]]) - - @param{ Mixed } regex string or rechain object
- @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
- @param{ Number } {m,n} <- n, n >= m
var r = ;console; // [0-7]console; // falseconsole; // true
<(...)>[{m,n}]
.p([re, [m, n]]) - - @param{ Mixed } regex string or rechain object
- @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
- @param{ Number } {m,n} <- n, n >= m
var r = ;console; // (?:abc)console; // falseconsole; // true
{m,n}
.n(m, n) - - @param{ Mixed } {m,n} <- m, m >= 0 OR string : ? + * {...} {...}?
- @param{ Number } {m,n} <- n, n >= m
var r = ;console; // \d+console; // \d{3,3}console; // [ '99' ]console; // [ '999' ]
.exact()
var r = ;console; // \dconsole; // trueconsole; // false
.go([opts])
var r = ;console; // String: \dconsole; // Regexp: /\d/console; // Regexp: /\d/gi
.opt(opts)
var r = ;console; // Regexp: /\d/giconsole; // Regexp: /\d/i
.e([str])
- @param { Mixed }
var r = ;console; // /\w/console; // /\w/giconsole; // falseconsole; // trueconsole; // [ 'abc' ]console; // nullconsole; // true
.is([str])
- same as previous
.contain([str])
- same as previous
.match([str])
- same as previous
.desc(str)
var r = ;console; // 'API test'
License
Copyright © 2015 Mark Zhan.
This project is available under the Apache license. See LICENSE for details.