predictype

predictype v0.13.0


predictype / predicates/regexps / regexpResult

Function: regexpResult()

regexpResult(pattern, oper, target): boolean

Defined in: predicates/regexps/regexpResult.ts:33

Evaluates a RegExp against a target string and validates the result using the specified operation.

Parameters

pattern

RegExp

The RegExp pattern to apply.

oper

RegExpResultOper

The result operation to perform (e.g. ‘tests’, ‘matches’).

target

string

The candidate string to validate.

Returns

boolean

True if the result operation is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const pattern = /cat/i;
const targetA = 'My Cat is sleeping';
const targetB = 'dog only';

regexpResult(pattern, 'tests', targetA); // true
regexpResult(pattern, 'not_matches', targetB); // true

Remarks

Supported Operators: