predictype / predicates/regexps / regexpResultSize
regexpResultSize(
pattern,oper,target,count):boolean
Defined in: predicates/regexps/regexpResultSize.ts:52
Counts RegExp matches on a target string and compares the count against a threshold.
RegExp
The RegExp pattern to apply.
The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).
string
The candidate string to validate.
number
The numeric threshold to compare against.
boolean
True if the count comparison is valid according to the operator, otherwise false.
If the operation is not recognized.
const pattern = /foo/g;
const target = 'foo-bar-foo';
const countA = 2;
const countB = 1;
regexpResultSize(pattern, 'size_equals', target, countA); // true
regexpResultSize(pattern, 'size_greater_than', target, countB); // true
Supported Operators: