icomefromthenet/reverse-regex

Convert Regular Expressions into text, for testing

v0.1.0.0 2018-08-15 07:15 UTC

This package is not auto-updated.

Last update: 2024-10-28 05:16:44 UTC


README

Build Status

Use Regular Expressions to generate text strings can be used in the following situations:

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

##Example

use ReverseRegex\Lexer;
use ReverseRegex\Random\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

jmceohykoa
aclohnotga
jqegzuklcv
ixdbpbgpkl
kcyrxqqfyw
jcxsjrtrqb
kvaczmawlz
itwrowxfxh
auinmymonl
dujyzuhoag
vaygybwkfm

Other examples

  1. Australian phone numbers
  2. Australian postcodes
  3. Mobile numbers

##Installing

To install use composer

{
  "require" : {
	"icomefromthenet/reverse-regex" : "dev-master"
    }
}

Writing a Regex

  1. Escape all meta-characters i.e. if you need to escape the character in a regex you will need to escape here.
  2. Not all meta-characters are suppported see list below.
  3. Use \X{####} to specify unicode value use [\X{####}-\X{####}] to specify range.
  4. Unicdoe \p not supported, I could not find a port of UCD to php, maybe in the future support be added.
  5. Quantifiers are applied to left most group, literal or character class.
  6. Beware of the + and * quantifers they apply a possible maxium number of occurances up to PHP_INT_MAX.

Regex Support