evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a pattern validation utility that converts regex source strings into regular expressions and validates input against those patterns.
Your task is to implement a pattern validator module that:
The module should provide a function that:
"^test.*", "[0-9]+")test methodtest method should accept an input string and return whether it matches// Case-sensitive matching
const validator1 = createValidator("^hello");
validator1.test("hello world"); // should return true
validator1.test("Hello world"); // should return false
// Case-insensitive matching
const validator2 = createValidator("^hello", { caseInsensitive: true });
validator2.test("hello world"); // should return true
validator2.test("Hello world"); // should return true
// Pattern validation
const validator3 = createValidator("[0-9]+");
validator3.test("123"); // should return true
validator3.test("abc"); // should return false"^test.*" (case-sensitive), it matches strings starting with "test" but not "Test" @test"[a-z]+" with case-insensitive option, it matches both "hello" and "HELLO" @test"\\d{3}", it matches exactly three digits like "123" @test/**
* Creates a pattern validator from a regex source string
* @param {string} pattern - The regex source pattern
* @param {object} options - Configuration options
* @param {boolean} options.caseInsensitive - Enable case-insensitive matching
* @returns {object} Validator object with test method
*/
function createValidator(pattern, options) {
// Implementation here
}
module.exports = { createValidator };Provides regex creation and pattern matching support.