2.0.26 • Published 3 months ago
execall2 v2.0.26
execall
Find multiple RegExp matches in a string
Instead of having to iterate over RegExp#exec
, immutable, and with a nicer result format.
Install
$ npm install execall2
Usage
import execall from 'execall2';
import * as execall from 'execall2';
import { execall } from 'execall2';
import execall = require('execall2');
const execall = require('execall2');
let t = execall(/(?<k>.)/g, '123456789');
console.dir(t, {
colors: true,
});
console.log('getOwnPropertyNames', Object.getOwnPropertyNames(t));
let {re, input} = t;
console.log('== hidden property ==');
console.dir({re, input}, {
colors: true,
});
console.log('== hidden property symbol ==');
// @ts-ignore
console.dir([execall.SYMBOL, t[0][execall.SYMBOL] === t], {
colors: true,
});
console.log('== JSON.stringify ==');
console.log(JSON.stringify(t));
[ [ '1', '1', index: 0, groups: { k: '1' }, match: '1', sub: [ '1' ] ],
[ '2', '2', index: 1, groups: { k: '2' }, match: '2', sub: [ '2' ] ],
[ '3', '3', index: 2, groups: { k: '3' }, match: '3', sub: [ '3' ] ],
[ '4', '4', index: 3, groups: { k: '4' }, match: '4', sub: [ '4' ] ],
[ '5', '5', index: 4, groups: { k: '5' }, match: '5', sub: [ '5' ] ],
[ '6', '6', index: 5, groups: { k: '6' }, match: '6', sub: [ '6' ] ],
[ '7', '7', index: 6, groups: { k: '7' }, match: '7', sub: [ '7' ] ],
[ '8', '8', index: 7, groups: { k: '8' }, match: '8', sub: [ '8' ] ],
[ '9', '9', index: 8, groups: { k: '9' }, match: '9', sub: [ '9' ] ] ]
getOwnPropertyNames [ '0', '1', '2', '3', '4', '5', '6', '7', '8', 'length', 're', 'input' ]
== hidden property ==
{ re: /(?<k>.)/g, input: '123456789' }
== hidden property symbol ==
[ Symbol(execall), true ]
== JSON.stringify ==
[["1","1"],["2","2"],["3","3"],["4","4"],["5","5"],["6","6"],["7","7"],["8","8"],["9","9"]]
execall(/(\d+)/g, '$200 and $400');
/*
[ [ '200',
'200',
index: 1,
groups: undefined,
match: '200',
sub: [ '200' ] ],
[ '400',
'400',
index: 10,
groups: undefined,
match: '400',
sub: [ '400' ] ] ]
*/
API
execall(re, input, options?: IExecAllOptions)
Returns an array of objects with a match, sub-matches, and index.
declare function execAll<T extends RegExp = RegExp>(inputRegExp: T | RegExp, input: string, options?: IExecAllOptions<T>): IMatches<T>;
re
Type: regexp
Regular expression to match against the input
.
input
Type: string
options
Type: IExecAllOptions
export interface IExecAllOptions<T extends RegExp = RegExp>
{
resetLastIndex?: boolean,
cloneRegexp?: ICloneRegexp<T>,
}
export interface ICloneRegexp<T extends RegExp = RegExp>
{
(inputRegExp: T | RegExp, ...argv): T
}
License
MIT © Sindre Sorhus
2.0.26
3 months ago
2.0.25
9 months ago
2.0.24
10 months ago
2.0.23
2 years ago
2.0.22
2 years ago
2.0.19
3 years ago
2.0.17
3 years ago
2.0.20
3 years ago
2.0.21
3 years ago
2.0.15
3 years ago
2.0.12
3 years ago
2.0.11
3 years ago
2.0.9
3 years ago
2.0.8
3 years ago
2.0.7
4 years ago
2.0.4
4 years ago
2.0.2
4 years ago
2.0.1
4 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.2
6 years ago
1.0.1
7 years ago
1.0.0
7 years ago