predictype

predictype v0.13.0


predictype / predicates/regexps / regexpResultSize

Function: 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.

Parameters

pattern

RegExp

The RegExp pattern to apply.

oper

RegExpResultSizeOper

The size operation to perform (e.g. ‘size_equals’, ‘size_greater_than’).

target

string

The candidate string to validate.

count

number

The numeric threshold to compare against.

Returns

boolean

True if the count comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

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

Remarks

Supported Operators: