testRegex

testRegex

Check if a string passes a specific regex

Import

import { testRegex } from '@fullstacksjs/toolbox';

Signature

function testRegex(regex: RegExp, str: string): boolean {}

Examples

const regexA = /a/g
testRegex(regexA, 'a') // true
regexA.lastIndex       // 0
 
const regexB = /b/g
testRegex(regexB, 'a') // false
regexB.lastIndex       // 0