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).
Use Case Alignment: The package’s new features (alternation, "not in range") expand its utility for complex regex-to-string generation, particularly for:
^(?!.*(abc|123)).{10}$).Laravel Synergy:
Str::random() (simpler, no constraints) remain stronger for most cases.Key Differentiator:
The "not in range" feature (e.g., \D but excluding [aeiou]) fills a niche for exclusion-based generation, which modern tools like Faker lack.
Dependency Risk:
composer.json or PHP 8.x support in release notes.mbstring, pcntl) may be needed for Laravel 5.x/6.x.Codebase Impact:
tests/, console/).string; may fail in PHP 7.4+ strict mode).RegexReverseException for invalid inputs).(a|aa)*[^b]).Testing Gaps:
Deprecation Risk:
Bugs/Edge Cases:
\D excluding [aeiou] and [0-9]).\p{L} not handled in PHP 5.6).(a|b|c|d)*).preg_last_error().Security:
PHP Version:
ext-mbstring).Laravel Compatibility:
app/Helpers/RegexHelper.php.php artisan make:regex-test-data.// app/Helpers/RegexTestHelper.php
use Niklongstone\RegexReverse\RegexReverse;
class RegexTestHelper {
public static function generateExcluding(string $pattern, string $exclusions): string {
return RegexReverse::reverse($pattern . '(?!' . $exclusions . ')');
}
}
Tooling:
composer.json in repo).Assessment Phase:
^(abc|def)\d{3}$ → abc123 or def456.\d{3}[^02468] → 1235 (excludes even digits).Integration Options:
composer.json with PHP 8.x support.vendor/package-name on Packagist.tests/ or console/ only.README.md.Deprecation Strategy:
preg_split() + array_filter()).Regex Limitations:
\K, (?R), \G.\p{L}, \X.(?<=...), (?<!...) (unless simple).Faker for basic cases, this package for exclusion-based needs.Laravel Ecosystem:
// In a Feature Test
$user = User::factory()->create([
'email' => RegexTestHelper::generateExcluding('\w+@\w+\.com', '[admin|root]')
]);
Phase 1 (Pilot):
Phase 2 (Stabilization):
How can I help you explore Laravel packages today?