Skip to content

isValidRegex

Checks if a string is a valid regex pattern.

Available since v1.9.0

import { isValidRegex } from '@helpers4/guard';
// or, from the all-in-one package (same code, one install):
import { isValidRegex } from 'helpers4/guard';
isValidRegex(value: string): boolean
ParameterTypeDescription
valuestringThe string to check

boolean — True if the string is a valid regex pattern

isValidRegex('[a-z]+') // => true
isValidRegex('.*')     // => true
isValidRegex('[')      // => false

View source on GitHub