dev-master
9999999-devRelax with this awesome library for working with regular expressions with PHP
MIT
The Development Requires
Relax with this awesome library for working with regular expressions with PHP
Deprecation Notice
Greppy is going to be phased away in favor of the PHPVerbalExpressions project., (*1)
FluentPattern
object.$p = new Relax\Greppy\Pattern();
With Greppy, you can define pattern objects – types – to easily define, reuse and maintain common patterns used in web applications., (*3)
If you use regex to match domain, for instance, instead of doing:, (*4)
preg_match("/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/i", $subject);
You may define a DomainPattern
type, such as:, (*5)
namespace Your\Namespace; use Relax\Greppy\Pattern; class DomainPattern implements Pattern { public function __toString() { return "/^(http|https|ftp)://([A-Z0-9][A-Z0-9_-]*(?:.[A-Z0-9][A-Z0-9_-]*)+):?(d+)?/?/"; } }
And use it like this:, (*6)
$domain = new Your\Namespace\DomainPattern(); $m = new Relax\Greppy\SimpleMatcher("http://www.google.com"); $m->caseless()->matches($domain); // true
The PHP way:, (*7)
preg_match("/./", "any"); // 1
The Greppy way:, (*8)
$m = new Relax\Greppy\SimpleMatcher("any"); $m->matches($p->any()); // true
The PHP way:, (*9)
preg_match("/\d/", "5"); // 1
The Greppy way:, (*10)
$m = new Relax\Greppy\SimpleMatcher("5"); $m->matches($p->digit()); // true
The PHP way:, (*11)
preg_match("/e/", "hey"); // 1
The Greppy way:, (*12)
$m = new Relax\Greppy\SimpleMatcher("hey"); $m->matches($p->literal("e")); // true
The PHP way:, (*13)
preg_match("/[abc]/", "anthem"); // 1
The Greppy way:, (*14)
$m = new Relax\Greppy\SimpleMatcher("anthem"); $m->matches($p->literal("a", "b", "c")); // true
The PHP way:, (*15)
preg_match("/[a-z]/", "any"); // 1
The Greppy way:, (*16)
$m = new Relax\Greppy\SimpleMatcher("any"); $m->matches($p->range("a", "z")); // true
The PHP way:, (*17)
preg_match("/z{3}/", "wazzzup"); // 1 preg_match("/z{2,4}/", "wazzzzup"); // 1
The Greppy way:, (*18)
$m = new Relax\Greppy\SimpleMatcher("wazzzup"); $m->matches($p->repetition("z", 3)); // true $m = new Relax\Greppy\SimpleMatcher("wazzzzup"); $m->matches($p->repetition("z", 2, 4)); // true
Relax with this awesome library for working with regular expressions with PHP
MIT