IComeFromTheNet.

Released ReverseRegex

  • Tags: php, regex,
  • Written on: October 18, 2012


I released a new library today ReverseRegex. It uses the regular expression syntax to populate a text string. I developed this component to include in my Faker project. By using a regex to populate a field I replace the 2 most commonly used column datatypes numeric and text, that is 2 less new DSL to learn.

Database testing tools like Faker on other platforms also use regex’s to define text patterns I have seen similar code implemented in .Net, Java and Perl and now php.

Other situations that my find this component useful are:

  1. Generating tests data for web forms
  2. Generating test data for regular expressions.
  3. Generating test data for databases.

This project is also the first time I have used travis-ci, It took a few tries to get the build working (problems with submodules) but that Build Status image is worth every second.

Example

<?php
use ReverseRegex\Lexer;
use PHPStats\Generator\SimpleRandom;
use ReverseRegex\Parser;
use ReverseRegex\Generator\Scope;
 
# load composer
require "vendor/autoload.php";
 
$lexer = new  Lexer('[a-z]{10}');
$gen   = new SimpleRandom(10007);
$result = '';
 
$parser = new Parser($lexer,new Scope(),new Scope());
$parser->parse()->getResult()->generate($result,$gen);
 
echo $result;

Produces Values Like

jmceohykoa, aclohnotga , jqegzuklcv , ixdbpbgpkl