@valtech-commerce/capturing-group-values
v1.0.0
Published
Extracts capturing group values via a regular expression
Downloads
9
Readme
@valtech-commerce/capturing-group-values
Extracts capturing group values via a regular expression
Install
$ npm install @valtech-commerce/capturing-group-values
Usage
import capturingGroupValues from '@valtech-commerce/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 © Valtech Canada inc.