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).
Modular Design: The package’s lexer/parser/generator architecture is highly composable, fitting seamlessly into Laravel’s service container or testing utilities. Components like Lexer, Parser, and Scope can be dependency-injected into Laravel’s test helpers, factories, or even custom service providers.
DatabaseSeeder or PestPHP’s beforeEach to auto-generate regex-compliant test data.Regex-Driven Abstraction: Eliminates boilerplate in test data generation, reducing cognitive load for developers writing validation tests. Ideal for projects with complex regex patterns (e.g., financial transaction IDs, nested validation rules).
Unicode and Hex Support: Fills a gap in Laravel’s ecosystem for internationalized applications or projects requiring non-ASCII test data (e.g., \X{00FF} for extended characters).
Alignment with Laravel Testing Stack:
it() blocks or custom test helpers.DataProvider or beforeTestMethod for dynamic test data.Illuminate\Database\Eloquent\Factories\Factory to generate regex-compliant attributes.Weaknesses:
\p{} Unicode properties, lookarounds, or backreferences—not a fit for projects relying on advanced regex (e.g., parsing nested JSON or complex validation logic).Fake or DatabaseMigrations).User::factory()->for($request->validated())).php artisan migrate:fresh --seed.\(.*\) for parentheses), adding a learning curve..*) may exhaust memory if not constrained (mitigated by the SimpleRandom fix in v0.6.0).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| PHP 8.1+ Requirement | High | Audit Laravel version compatibility; plan upgrade if needed (Laravel 10.x+ supports PHP 8.1). |
| Regex Limitations | Medium | Document unsupported features (e.g., \p{L}) and provide fallbacks (e.g., custom generators). |
| Memory Usage | Medium | Enforce bounded quantifiers in CI/CD (e.g., a{1,100} instead of a*). |
| Learning Curve | Low | Create internal docs or Laravel-specific examples (e.g., "Generating Postcodes for Seeding"). |
| Maintenance Overhead | Low | Leverage Composer scripts (phpstan-baseline) to enforce quality without manual effort. |
| Laravel Ecosystem Gaps | Medium | Build custom facades or testing helpers to bridge Laravel-specific needs (e.g., factory integration). |
Validation Testing:
Technical Debt:
Compliance/Localization:
Laravel Ecosystem:
Long-Term Viability:
\p{} support)?"Primary Use Cases in Laravel:
tests/Feature/ or tests/Unit/ with regex-generated strings.PostcodeValidator tests.DatabaseSeeder or model factories to populate test databases with regex-compliant data.users table with regex-generated email addresses ([a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$)./users endpoint with regex-generated JSON bodies.FormRequest validation rules (e.g., Rule::phoneNumber, custom regex rules).Compatibility with Laravel Components:
| Laravel Component | Integration Strategy | Example |
|---|---|---|
| PestPHP | Use in it() blocks or custom test helpers. |
php it('validates postcodes', fn () => $request->assertValid(['postcode' => ReverseRegex::generate('[0-9]{4}')])); |
| PHPUnit | Integrate with DataProvider or beforeTestMethod. |
php public function postcodeProvider() { return [['1234'], ['5678']]; } |
| Factories | Extend Illuminate\Database\Eloquent\Factories\Factory to generate regex attributes. |
php public function definition() { return ['postcode' => ReverseRegex::generate('[0-9]{4}')]; } |
| Migrations | Use in DatabaseSeeder or custom seeders. |
php $this->call(ReverseRegexPostcodeSeeder::class); |
| Form Requests | Generate test data for FormRequest::rules(). |
php $request->assertValid(['ssn' => ReverseRegex::generate('\\d{3}-\\d{2}-\\d{4}')]); |
| API Testing (PestPHP) | Generate dynamic payloads for HTTP tests. | php test('creates user with valid email', fn () => $this->post('/users', ['email' => ReverseRegex::generate('[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$')])); |
Dependencies:
composer require ilario-pierbattista/reverse-regex).How can I help you explore Laravel packages today?