levu42/regexpander

PHP library that expands a regular expression into a random string that matches this pattern

v0.0.1 2022-01-09 22:20 UTC

README

Latest Version on Packagist Tests Total Downloads

PHP library that expands a regular expression into a random string that matches this pattern

Installation

You can install the package via composer:

composer require levu42/regexpander

Usage

$phoneNumber = Levu42\RegExpander::generate('\d{3}-\d{4}-\d{3}');
echo $phoneNumber;

Supported regexes

  • Character classes: \d, \D, \s, \S, \w, \W, .
    • \d = [0-9]
    • \D = [^0-9]
    • \s = [ \n\r]
    • \S = [^ \n\r]
    • \w = [a-zA-Z0-9_]
    • \W = [^a-zA-Z0-9_]
    • . = [anything]
  • Custom character classes, e.g. [0-9a-f], [^x]
  • Alternatives: a|b
  • Multipliers: a+, a*, a?, a{2,5}
  • Subpatterns: (a|b|\s)

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.