
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Regex Chain - A new method for regular expressions.
npm i rechain --save
var r = require('rechain');
var ipv4 = r()
.a('25[0-5]')
.or('2[0-4][0-9]')
.or('1[0-9][0-9]')
.or('[1-9][0-9]')
.or('[0-9]')
.p()
ipv4 = ipv4.a(r('\\.').a(ipv4).p(0,3));
console.log(ipv4.regex); // (?: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.log(ipv4.is('192.168.1.1')); // true
console.log(ipv4.contain('192.168.1.a 192.168.1.1')); // true
console.log(ipv4.match('192.168.1.a 192.68.1.1-8.8.8.8.')); // [ '192.68.1.1', '8.8.8.8' ]
console.log(ipv4.e().test('192.168.1.1')); // true
// check url
var 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 = r().a(ipv4).or().p('localhost').or().a(host).a(domain).a(tld)
var url = r().a(protocol).a(auth).p(url).a(port).a(path)
console.log(url.is('http://markzhan.com')); // true
<...>[{m,n}]
var r = require('rechain');
console.log(r().a('\\d').regex); // \d
console.log(r().a('\\d').is('8')); // true
console.log(r().a(r('\\d')).is('8')); // true
<|...>[{m,n}]
var r = require('rechain');
console.log(r('hello').or('world').regex); // hello|world
console.log(r('hello').or('world').match('hello')); // [ 'hello' ]
console.log(r('hello').or('world').match('world')); // [ 'world' ]
<[...]>[{m,n}]
var r = require('rechain');
console.log(r().m('0-7').regex); // [0-7]
console.log(r().m('0-7').is('8')); // false
console.log(r().m(r('0-9')).is('8')); // true
<(...)>[{m,n}]
var r = require('rechain');
console.log(r().p('abc').regex); // (?:abc)
console.log(r().p('abc').contain('123')); // false
console.log(r().p(r('abc')).contain('abc123')); // true
{m,n}
var r = require('rechain');
console.log(r('\\d').n('+').regex); // \d+
console.log(r('\\d').n(3,3).regex); // \d{3,3}
console.log(r('\\d').n('+').match('99')); // [ '99' ]
console.log(r('\\d').n(3,3).match('99.999')); // [ '999' ]
var r = require('rechain');
console.log(r('\\d').regex); // \d
console.log(r('\\d').contain('8.8')); // true
console.log(r('\\d').exact().contain('8.8')); // false
var r = require('rechain');
console.log(r('\\d').regex); // String: \d
console.log(r('\\d').go().regex); // Regexp: /\d/
console.log(r('\\d').go('ig').regex); // Regexp: /\d/gi
var r = require('rechain');
console.log(r('\\d').opt('ig').go().regex); // Regexp: /\d/gi
console.log(r('\\d').opt('g').go('i').regex); // Regexp: /\d/i
var r = require('rechain');
console.log(r('\\w').e()); // /\w/
console.log(r('\\w').e('ig')); // /\w/gi
console.log(r('\\w').e('abc').is()); // false
console.log(r('\\w').e('abc').contain()); // true
console.log(r('abc').e('abc').match()); // [ 'abc' ]
console.log(r('\\d').e('abc').match()); // null
console.log(r('\\d').e().test('8')); // true
var r = require('rechain');
console.log(r().desc('API test').description); // 'API test'
Copyright © 2015 Mark Zhan.
This project is available under the Apache license. See LICENSE for details.
FAQs
Regex Chain - A new method for regular expressions
The npm package rechain receives a total of 0 weekly downloads. As such, rechain popularity was classified as not popular.
We found that rechain demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.