Wallogit.com
2017 © Pedro Peláez
REBuilder is a PHP library to build and parse regular expressions
REBuilder is a PHP 5.3+ library to build and parse regular expressions, (*1)
Include the following requirement to your composer.json:, (*2)
{
"require": {
"mck89/rebuilder": "dev-master"
}
}
Run composer install and include the autoloader:, (*3)
require_once "vendor/autoload.php";
REBuilder's parser builds a tree structure starting from a regular expression. For example this code:, (*4)
//Parse the regular expression
$regex = REBuilder\REBuilder::parse("/parse\s+me/");
Generates this structure:, (*5)
REBuilder\Pattern\Regex
getStartDelimiter() => "/"
getEndDelimiter() => "/"
getChildren() => array(
REBuilder\Pattern\Char
getChar() => "parse"
REBuilder\Pattern\GenericCharType
getIdentifier() => "s"
getRepetition() => REBuilder\Pattern\Repetition\OneOrMore
REBuilder\Pattern\Char
getChar() => "me"
)
REBuilder allows you to build regular expressions with object oriented PHP:, (*6)
//Create an empty regular expression object
$regex = REBuilder\REBuilder::create();
$regex->addCharAndContinue("parse")
->addGenericCharType("s")
->setRepetition("+")
->getParent()
->addCharAndContinue("me");
echo $regex->render(); //"/parse\s+me/"