predictype

predictype v0.13.0


predictype / predicates/regexps/regexpResultRange / regexpResultRange

Function: regexpResultRange()

regexpResultRange(pattern, oper, target, min, max): boolean

Defined in: predicates/regexps/regexpResultRange.ts:54

Counts RegExp matches on a target string and validates whether the count is within a range.

Parameters

pattern

RegExp

The RegExp pattern to apply.

oper

RegExpResultRangeOper

The range operation to perform (e.g. ‘between’, ‘strict_between’).

target

string

The candidate string to validate.

min

number

The lower bound of the range.

max

number

The upper bound of the range.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const pattern = /item/g;
const target = 'item,item,item';
const minA = 2;
const maxA = 4;
const minB = 3;
const maxB = 5;

regexpResultRange(pattern, 'between', target, minA, maxA); // true
regexpResultRange(pattern, 'strict_between', target, minB, maxB); // false

Remarks

Supported Operators: