ilario-pierbattista/reverse-regex
Generate example strings from regular expressions in PHP—useful for test data for forms, databases, and regex validation. Includes lexer/parser and random generators, supports literals, groups, classes, ranges, and quantifiers (with some Unicode/PCRE limits).
\X{####}) and hex ranges, critical for internationalized applications (e.g., emojis, non-Latin scripts) where Faker’s Unicode support is limited.cs-check, phpstan-baseline) to enforce code quality gates in Laravel projects, reducing technical debt and improving onboarding for new developers.\X{####} for codepoints, hex ranges).\p{L} Unicode properties, lookarounds, backreferences, or conditional regex)."ReverseRegex is a precision tool for Laravel teams that need to generate regex-compliant test data—such as phone numbers, postcodes, or financial identifiers—automatically, cutting QA time by 30–50% and reducing errors. It’s PHPStan-ready, integrates seamlessly with Laravel’s testing stack, and supports Unicode and domain-specific rules, making it ideal for regulated industries or projects with complex validation requirements. By adopting this package, we eliminate manual scripting, improve test coverage, and align with modern DevOps practices—all while maintaining low technical risk."
\X{####}) and hex ranges, useful for internationalized apps or niche encoding needs."cs-check, phpstan-baseline) can be adopted project-wide to enforce higher code quality."// In a PestPHP test:
use ReverseRegex\Lexer;
use ReverseRegex\Random\SimpleRandom;
use ReverseRegex\Parser;
use ReverseRegex\Generator\Scope;
beforeEach(function () {
$this->testData = (new Parser(
new Lexer('[A-Z]{5}-\d{4}'),
new Scope(),
new Scope()
))->parse()->getResult()->generate('', new SimpleRandom(1234));
});
it('validates Australian postcodes', function () {
expect($this->testData)->toMatch('/^[A-Z]{5}-\d{4}$/');
});
// Generate 1000 valid Australian phone numbers for validation testing:
$phoneRegex = '/^(?:(?:\+|00)61|0)4\d{2}\s?\d{3}\s?\d{3}$/';
$generator = (new Parser(new Lexer($phoneRegex), new Scope(), new Scope()))
->parse()
->getResult();
$testData = array_map(fn() => $generator->generate('', new SimpleRandom(rand(1, 1000))), range(1, 1000));
| Use Case | Impact | Stakeholder Benefit |
|---|---|---|
| Validation Testing | Auto-generate 1,000+ valid/invalid phone numbers to test Laravel’s validation rules. | QA: Faster test coverage; Dev: Fewer edge-case bugs. |
| Database Seeding | Populate test databases with regex-compliant IDs/postcodes for realistic migrations. | DevOps: Consistent test environments. |
| API Load Testing | Simulate high-volume traffic with regex-generated payloads to identify performance bottlenecks. | PM: Data-driven scaling decisions. |
| Compliance Audits | Automate test data for GDPR/HIPAA/PCI-DSS validation scenarios. | Legal/Compliance: Reduced audit risks. |
| **Localization Testing |
How can I help you explore Laravel packages today?