PHPackages                             gherkins/regexpbuilderphp - 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. gherkins/regexpbuilderphp

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

gherkins/regexpbuilderphp
=========================

PHP port of thebinarysearchtree/regexpbuilderjs

2.2.0(6mo ago)1.3k189.0k↓60.6%471MITPHPPHP ^8.2CI passing

Since Feb 19Pushed 6mo ago48 watchersCompare

[ Source](https://github.com/gherkins/regexpbuilderphp)[ Packagist](https://packagist.org/packages/gherkins/regexpbuilderphp)[ Docs](https://github.com/gherkins/regexpbuilderphp/)[ RSS](/packages/gherkins-regexpbuilderphp/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (2)Versions (15)Used By (1)

```
 ____            _____            ____        _ _     _           ____  _   _ ____
|  _ \ ___  __ _| ____|_  ___ __ | __ ) _   _(_) | __| | ___ _ __|  _ \| | | |  _ \
| |_) / _ \/ _` |  _| \ \/ / '_ \|  _ \| | | | | |/ _` |/ _ \ '__| |_) | |_| | |_) |
|  _ <  __/ (_| | |___ >   RegExpBuilder integrates regular expressions into the programming language, thereby making them easy to read and maintain. Regular Expressions are created by using chained methods and variables such as arrays or strings.

Installation
------------

[](#installation)

```
composer req gherkins/regexpbuilderphp
```

Or download [the appropriate release](https://github.com/gherkins/regexpbuilderphp/releases/latest) and require `RegExpBuilder.php` and `RegExp.php` from `/src`.

Documentation
-------------

[](#documentation)

Examples
--------

[](#examples)

```
use Gherkins\RegExpBuilderPHP;
$builder = new RegExpBuilder();
```

### Validation

[](#validation)

```
$regExp = $builder
    ->startOfInput()
    ->exactly(4)->digits()
    ->then("_")
    ->exactly(2)->digits()
    ->then("_")
    ->min(3)->max(10)->letters()
    ->then(".")
    ->anyOf(array("png", "jpg", "gif"))
    ->endOfInput()
    ->getRegExp();

//true
$regExp->matches("2020_10_hund.jpg");
$regExp->matches("2030_11_katze.png");
$regExp->matches("4000_99_maus.gif");

//false
$regExp->matches("123_00_nein.gif");
$regExp->matches("4000_0_nein.pdf");
$regExp->matches("201505_nein.jpg");
```

### Search

[](#search)

```
$regExp = $builder
    ->multiLine()
    ->globalMatch()
    ->min(1)->max(10)->anythingBut(" ")
    ->anyOf(array(".pdf", ".doc"))
    ->getRegExp();

$text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy SomeFile.pdf eirmod tempor invidunt ut labore et dolore
magna aliquyam erat, sed diam voluptua. At vero eos et accusam
et justo duo dolores et ea rebum. doc_04.pdf Stet clita kasd File.doc.'

$matches = $regExp->findIn($text);

//true
($matches[0] === "SomeFile.pdf");
($matches[1] === "doc_04.pdf");
($matches[2] === "File.doc");
```

### Replace

[](#replace)

```
$regExp = $builder
    ->min(1)
    ->max(10)
    ->digits()
    ->getRegExp();

$text = "98 bottles of beer on the wall";

$text = $regExp->replace(
    $text,
    function ($match) {
        return (int)$match + 1;
    }
);

//true
("99 bottles of beer on the wall" === $text);
```

### Validation with multiple patterns

[](#validation-with-multiple-patterns)

```
$a = $builder
    ->startOfInput()
    ->exactly(3)->digits()
    ->anyOf(array(".pdf", ".doc"))
    ->endOfInput();

$b = $builder
    ->getNew()
    ->startOfInput()
    ->exactly(4)->letters()
    ->then(".jpg")
    ->endOfInput();

$regExp = $builder
    ->getNew()
    ->eitherFind($a)
    ->orFind($b)
    ->getRegExp();

//true
$regExp->matches("123.pdf");
$regExp->matches("456.doc");
$regExp->matches("bbbb.jpg");
$regExp->matches("aaaa.jpg");

//false
$regExp->matches("1234.pdf");
$regExp->matches("123.gif");
$regExp->matches("aaaaa.jpg");
$regExp->matches("456.docx");
```

Take a look at the [tests](tests/RegExpBuilderTest.php) for more examples

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance66

Regular maintenance activity

Popularity58

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 92.7% 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.

###  Release Activity

Cadence

Every ~304 days

Recently: every ~271 days

Total

14

Last Release

197d ago

Major Versions

0.8.0 → 1.0.02021-01-11

1.1.0 → 2.0.02023-01-08

PHP version history (5 changes)0.7.0PHP &gt;=5.3.0

0.8.0PHP ^7.0

1.0.0PHP ^7.0|^8.0

2.0.0PHP ^8.0

2.2.0PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![gherkins](https://avatars.githubusercontent.com/u/824927?v=4)](https://github.com/gherkins "gherkins (202 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![simp42](https://avatars.githubusercontent.com/u/3244017?v=4)](https://github.com/simp42 "simp42 (3 commits)")[![ELD](https://avatars.githubusercontent.com/u/650044?v=4)](https://github.com/ELD "ELD (1 commits)")

---

Tags

human-readablephpregexregular-expressionregular-expressionsphpbuilderregex

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gherkins-regexpbuilderphp/health.svg)

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

###  Alternatives

[reisraff/phulp

The task manager for PHP

29412.2k10](/packages/reisraff-phulp)[selvinortiz/flux

Fluent regular expressions in PHP.

3382.1k3](/packages/selvinortiz-flux)[godbout/dash-docset-builder

Dash (LOVE) Docset Builder in PHP (LOVE).

1263.6k](/packages/godbout-dash-docset-builder)

PHPackages © 2026

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