Test name | Executions per second |
---|---|
regexp | 597486.0 Ops/sec |
many regexps | 308116.1 Ops/sec |
var strings = [
'bbbb',
'AAbb',
'aaBB',
'AAbb11',
'aaBB11',
'11aaBB',
'aaAAbb',
'aaaa'
];
const matches = strings.filter(s => /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d$@!%*#?&-_]{4,14}$/.test(s));
if (matches.length !== 3) {
throw 'invalid number of matches: ' + matches;
}
const matches = strings.filter(s => {
return /^[\w$@!%*#?&-]{4,14}$/.test(s) &&
/[A-Z]/.test(s) &&
/[a-z]/.test(s) &&
/[0-9]/.test(s);
});
if (matches.length !== 3) {
throw 'invalid number of matches: ' + matches;
}