PHPackages                             relaxphp/greppy - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. relaxphp/greppy

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

relaxphp/greppy
===============

Relax with this awesome library for working with regular expressions with PHP

90174PHP

Since Mar 20Pushed 10y ago5 watchersCompare

[ Source](https://github.com/drgomesp/Greppy)[ Packagist](https://packagist.org/packages/relaxphp/greppy)[ RSS](/packages/relaxphp-greppy/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Greppy
======

[](#greppy)

> ## Deprecation Notice
>
> [](#deprecation-notice)

> Greppy is going to be phased away in favor of the [PHPVerbalExpressions](https://github.com/VerbalExpressions/PHPVerbalExpressions) project.

[![Build Status](https://camo.githubusercontent.com/50aacc9f30f44b04975528997569106c2fd6efb9c61e696d464d15c2bfe4f6a3/68747470733a2f2f7472617669732d63692e6f72672f6472676f6d6573702f6772657070792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/drgomesp/greppy)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/60f1edb75a54e3999fae65acafabafb1c2eec28e379bf0b29cd21cb7fd3c1e45/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6472676f6d6573702f4772657070792f6261646765732f7175616c6974792d73636f72652e706e673f733d32656536353830346362633063323233373131643936633134333637646433376132303238323464)](https://scrutinizer-ci.com/g/drgomesp/Greppy/)[![Latest Unstable Version](https://camo.githubusercontent.com/80a0ebb4e94bbd5b788cf0409a4b645b2a3417e43df74408d9d1f13d723577b4/68747470733a2f2f706f7365722e707567782e6f72672f72656c61787068702f6772657070792f762f756e737461626c652e706e67)](https://packagist.org/packages/relaxphp/greppy)[![License](https://camo.githubusercontent.com/a9310cb162b6b37da44244b2f7ea15fbdf44090172b10321384794c4ebe96fd7/68747470733a2f2f706f7365722e707567782e6f72672f72656c61787068702f6772657070792f6c6963656e73652e706e67)](https://packagist.org/packages/relaxphp/greppy)[![SensioLabsInsight](https://camo.githubusercontent.com/01f835f86c15c1ada31ffc08f26b97568c5c46d3e222d38fd878b065a0085280/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f34616563343933622d623766332d346534332d383431322d3336316238346133326336662f6d696e692e706e67)](https://insight.sensiolabs.com/projects/4aec493b-b7f3-4e43-8412-361b84a32c6f/mini.png)

Why use Greppy?
---------------

[](#why-use-greppy)

- Isolate your regex patterns and matching so they can be easily mocked inside unit tests
- Represent important and recurrent patterns with custom pattern classes
- Write more human-readable regular expressions with a fluent API using the `FluentPattern` object.

Feature Guide
-------------

[](#feature-guide)

### Bootstrap

[](#bootstrap)

```
$p = new Relax\Greppy\Pattern();
```

### Custom pattern objects

[](#custom-pattern-objects)

With Greppy, you can define pattern objects – types – to easily define, reuse and maintain common patterns used in web applications.

If you use regex to match domain, for instance, instead of doing:

```
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:

```
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:

```
$domain = new Your\Namespace\DomainPattern();
$m = new Relax\Greppy\SimpleMatcher("http://www.google.com");
$m->caseless()->matches($domain); // true
```

### The predefined Pattern object

[](#the-predefined-pattern-object)

#### Matching any single character

[](#matching-any-single-character)

The PHP way:

```
preg_match("/./", "any"); // 1
```

The Greppy way:

```
$m = new Relax\Greppy\SimpleMatcher("any");
$m->matches($p->any()); // true
```

#### Matching any digit

[](#matching-any-digit)

The PHP way:

```
preg_match("/\d/", "5"); // 1
```

The Greppy way:

```
$m = new Relax\Greppy\SimpleMatcher("5");
$m->matches($p->digit()); // true
```

#### Matching a literal

[](#matching-a-literal)

The PHP way:

```
preg_match("/e/", "hey"); // 1
```

The Greppy way:

```
$m = new Relax\Greppy\SimpleMatcher("hey");
$m->matches($p->literal("e")); // true
```

#### Matching a group of literals

[](#matching-a-group-of-literals)

The PHP way:

```
preg_match("/[abc]/", "anthem"); // 1
```

The Greppy way:

```
$m = new Relax\Greppy\SimpleMatcher("anthem");
$m->matches($p->literal("a", "b", "c")); // true
```

#### Matching a range

[](#matching-a-range)

The PHP way:

```
preg_match("/[a-z]/", "any"); // 1
```

The Greppy way:

```
$m = new Relax\Greppy\SimpleMatcher("any");
$m->matches($p->range("a", "z")); // true
```

#### Matching a repetition

[](#matching-a-repetition)

The PHP way:

```
preg_match("/z{3}/", "wazzzup"); // 1
preg_match("/z{2,4}/", "wazzzzup"); // 1
```

The Greppy way:

```
$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
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b192a109e64fa823a99bff505d805a4dbeb219e67d51c3359c6908dedf74bd48?d=identicon)[drgomesp](/maintainers/drgomesp)

---

Top Contributors

[![drgomesp](https://avatars.githubusercontent.com/u/696982?v=4)](https://github.com/drgomesp "drgomesp (53 commits)")[![gabrielsch](https://avatars.githubusercontent.com/u/1733354?v=4)](https://github.com/gabrielsch "gabrielsch (1 commits)")

### Embed Badge

![Health badge](/badges/relaxphp-greppy/health.svg)

```
[![Health](https://phpackages.com/badges/relaxphp-greppy/health.svg)](https://phpackages.com/packages/relaxphp-greppy)
```

###  Alternatives

[nyholm/effective-interest-rate

A library to calculate effective interest rate. Also know as XIRR or effective APR.

24169.4k](/packages/nyholm-effective-interest-rate)[barnabywalters/mf-cleaner

Cleans up microformats2 array structures

146.8k4](/packages/barnabywalters-mf-cleaner)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
