niklongstone/regex-reverse
Generate random strings that match a given PCRE-style regex. Supports common character classes (\d, \w, \s), ranges, groups, alternation, and quantifiers (*, +, ?, {n,m}). Simple API: RegRev::generate($pattern).
|) and not in range (^ outside character classes) features expand support for more complex validation patterns (e.g., conditional logic like ^(start|middle|end)$ or negated ranges like [^a-z]). This justifies adoption for teams with moderate-to-advanced regex needs (e.g., multi-condition form validation, parsing structured logs).Adopt if:
^(admin|user|guest)$ for role-based validation) or negated character ranges (e.g., [^<>&] for sanitizing HTML inputs).^(v1|v2)\.\d{1,2}$ for versioning).Look elsewhere if:
^\d{5}$ for ZIP codes) and rarely change.(?=.*\d)(?=.*[a-z]) for password complexity).Faker + PHPUnit extensions) or performance benchmarking (use PCRE profiling tools).For Executives:
"The latest update to this package adds support for conditional regex patterns (e.g., ^(start|middle|end)$) and negated ranges (e.g., [^a-z]), which are critical for validating complex business rules—like role-based access or input sanitization. For example, if our new compliance module uses regex to block disallowed characters in patient notes, this tool can automatically generate test strings that should fail validation, catching edge cases before they hit production. It’s a 10-minute setup that could save hours in debugging and reduce compliance risks. Given its PHP-native integration, the risk is minimal, and the ROI is clear for teams writing regex-heavy validation logic."
For Engineering: *"The 0.4.0 release closes critical gaps for teams using non-trivial regex:
|): Now you can test patterns like ^(admin|user|guest)$ without manually writing test cases for each branch.[^...]): Perfect for blacklist validation (e.g., [^<>&] to strip HTML tags from user inputs).
Why this matters:PHPUnit extensions, but that’d take 3–5 dev days vs. zero here.
Proposal: Pilot this for our compliance module and user input validation—high-risk areas where regex bugs are costly."*For Developers: *"This update makes the package useful for real-world regex—no more ignoring it for ‘simple’ cases! Key improvements:
Alternation (|):
$regex = '/^(admin|user|guest)$/';
$generator = new \NikLongstone\RegexReverse\Generator($regex);
$validRole = $generator->generate(); // Outputs: 'admin' (or 'user', 'guest')
Use case: Testing role-based validation or multi-option fields.
Not in range ([^...]):
$regex = '/^[^<>&]+$/'; // Blocks HTML tags
$safeInput = $generator->generate(); // Outputs: 'Hello World' (no `<`, `>`, `&`)
Use case: Sanitizing user inputs for security/compliance.
When to avoid:
Try it for:
How can I help you explore Laravel packages today?