icomefromthenet/reverse-regex
Generate sample strings from regular expressions for test data and validation. ReverseRegex parses a supported subset of regex syntax (literals, groups, character classes, quantifiers, escapes, some Unicode via \X{####}) and outputs randomized matching text via PHP generators.
Automated Test Data Generation for Validation Logic:
["123-456-7890", "987-654-3210"] with dynamic generation from /^\d{3}-\d{3}-\d{4}$/ in PHPUnit tests.Compliance and Edge-Case Testing:
^\d{16}$ (credit card numbers) with inputs like 1234567890123456 (valid) and 123 (invalid).Mock Data for Staging/Development:
^\d{4}$, phone numbers ^04\d{8}$). Avoids production data leaks while maintaining realism.DatabaseSeeder or Factories to auto-generate test datasets for feature branches.Build vs. Buy Decision:
\p{L}) or custom quantifier logic (e.g., bounded */+). Consider forking the repo to add missing features.Performance Optimization:
\d{1000}) to stress-test regex-based sanitizers.Developer Experience (DX):
$fakeName = generateFromRegex('^[A-Za-z]{2,50}$'); // Self-docs: "Names are 2–50 letters"
str_repeat() or range() calls with declarative regex patterns.FormRequest, API payload schemas, database constraints). Example: E-commerce platforms with SKU formats like ^[A-Z]{2}\d{6}$.["user1", "user2", ...]) or using brittle generators like str_repeat("a", 10).\p{L} (e.g., emoji, CJK) or complex grapheme clusters. Workaround: Use hex ranges like \X{00C0}-\X{00FF} for accented characters.*/+ are avoided in favor of bounded ranges (e.g., {1,10}). Benchmark with your regex patterns to ensure no PHP_INT_MAX issues.\A, \z, \Z (start/end of string).(?=...), (?!...) (positive/negative lookaheads).\1, \2 (capturing groups).(a|b){2,}(c|d){1,3}) may lead to unexpected generation behavior. Consider training or simpler alternatives like Faker.*"This package automates the generation of test data using the same regex rules our application validates against—saving QA teams dozens of hours annually while improving test coverage. For example, instead of manually creating 100 test phone numbers, we’ll generate them dynamically in CI, catching edge cases like invalid formats or boundary values.
Why It Matters:
\d{1000}) to find vulnerabilities early.Investment:
Risk Mitigation:
*"ReverseRegex lets us generate test strings from regex patterns, which is perfect for:
a{100} to test max-length limits or \d{10} for numeric fields.^[A-Z]{2}\d{6}$ (SKU format) with valid/invalid inputs.\d{1000} to trigger stack overflows).How to Use It:
// Generate a random 10-digit number
$fakeId = generateFromRegex('\d{10}');
// Generate an Australian postcode (e.g., 2000)
$fakePostcode = generateFromRegex('\d{4}');
// Generate a phone number (e.g., 0412 345 678)
$fakePhone = generateFromRegex('04\d{2} \d{3} \d{3}');
Tradeoffs:
\p{L} support (workaround: use \X{} for specific ranges).*/+ can hit PHP_INT_MAX—use {1,10} instead.(a|b){2,}(c|d){1,3}).Proposal:
TestDataGenerator) for consistency.Alternatives:
Next Steps:
How can I help you explore Laravel packages today?