ConstRegExpSchema.parse(/abc/gi); // ✓ Valid (literal syntax)
RegExpSchema.parse(new RegExp('abc', 'gi')); // ✓ Valid (constructor)
RegExpSchema.parse(/test/); // ✓ Valid (no flags)
RegExpSchema.parse(new RegExp('')); // ✓ Valid (empty pattern)
RegExpSchema.parse('abc'); // ✗ Throws validation error (string)
RegExpSchema.parse(/abc/.source); // ✗ Throws validation error (string pattern)
RegExpSchema.parse({}); // ✗ Throws validation error (object)
import { createAssertion, use } from 'bupkis';
import { RegExpSchema } from 'bupkis/schema';
const globalRegexAssertion = createAssertion(
  [RegExpSchema, 'to be a RegExp with the global flag'],
  RegExpSchema.refine((subject) => subject.flags.includes('g')),
);
const { expect } = use([globalRegexAssertion]);
expect(/pants/g, 'to be a RegExp with the global flag');
A Zod schema that validates RegExp instances.
This schema validates values that are instances of the RegExp class, including regular expressions created with both literal syntax (
/pattern/flags) and the RegExp constructor (new RegExp(pattern, flags)). It ensures the validated value is a proper regular expression object with all associated methods and properties.