kudos / regmatch
A class that takes as input a pseudo regular expression and outputs a random string that would match it.
This package is auto-updated.
Last update: 2017-05-07 07:20:20 UTC
README
A package to demonstrate returning a random string from a provided regex pattern
This package contains one simple class, Regmatch
, which accepts a simple regular expression in a form of a string, and returns a pseudo-random string that matches the provided regex pattern.
Specification
Create a class that takes as input a pseudo regular expression and outputs a random string that would match it. Without using 3rd party libraries The pseudo regular expression syntax contains literals as well character classes followed by optional quantifiers. Character classes are of the simple form [abc] or [a-z]. The quantifiers use either the form {5} or {3,5}. No other meta characters nor groups are supported.
Examples: "foo [bar] baz", "line [0-9]{3}", "[a-z]{1,10}"
Example output: "foo r baz", "line 123", "asjld"
Installation
The easiest method to install this package is from the Command Line. Cd into your project's root directory and enter the following command:
composer require kudos/regmatch
Another method is to require the package manually. In your project's composer.json
file simply add this package to the required section:
"require": {
"kudos/regmatch": "*"
}
Afterwards, it is required to run composer update
.
Usage
In order to use this class, add it to the use
statement in your class:
<?php
use Kudos\Regmatch;
class MyCustomClass
{
//
}
The class provides two public properties: input
and output
. input
returns the initial regex pattern, while output
provides the expected result:
<?php
use Kudos\Regmatch;
class MyCustomClass
{
public $myRegex;
public myMethod()
{
$this->myRegex = new Regmatch('foo [bar] baz');
// Echoes 'foo [bar] baz'
echo $this->myRegex->input;
// Echoes 'foo r baz'
echo $this->myRegex->output;
}
}
Other notes
The package's Git repository can be found at
https://bitbucket.org/digitalmagic/task-1/
Feel free to fork it, send pull requests, report issues or provide any kind of feedback.