1.0.0 • Published 4 years ago

@absolunet/capturing-group-values v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

@absolunet/capturing-group-values

npm npm dependencies npms Travis CI

Extracts capturing group values via a regular expression

Install

$ npm install @absolunet/capturing-group-values

Usage

import capturingGroupValues from '@absolunet/capturing-group-values';

const pattern = /(?<alpha>[a-z]+)?:(?<num>\d+)?/u;

console.log(capturingGroupValues('',        pattern));  // {}
console.log(capturingGroupValues(':',       pattern));  // {}
console.log(capturingGroupValues('abc',     pattern));  // {}
console.log(capturingGroupValues('123',     pattern));  // {}
console.log(capturingGroupValues('abc:xyz', pattern));  // { alpha: 'abc' }
console.log(capturingGroupValues('123:789', pattern));  // { num: '789' }
console.log(capturingGroupValues('abc:789', pattern));  // { alpha: 'abc', num: '789' }

Documentation

View documentation

License

MIT © Absolunet