PHPackages                             tea/regex - 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. tea/regex

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

tea/regex
=========

A clean interface for building and working with regular expressions. Lightweight wrapper for the built in PCRE library (preg\_\* functions).

056[1 issues](https://github.com/TeaLabs/regex/issues)PHP

Since Jan 9Pushed 9y ago2 watchersCompare

[ Source](https://github.com/TeaLabs/regex)[ Packagist](https://packagist.org/packages/tea/regex)[ RSS](/packages/tea-regex/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Regex
=====

[](#regex)

PHP comes with a built-in regular expression library *(`PCRE`)*, which provides the `preg_*` functions. Most of the time, these functions require some odd patterns like passing variables by reference and treating `false` or `null` values as errors. To make working with regex a bit more developer-friendly, `tea/regex` provides a clean interface for the `preg_*` functions as well as a human-readable API for building regular expressions.

Basic Usage.
------------

[](#basic-usage)

To build and work with regular expressions, `tea\regex` provides a couple of flexible components.

- The `RegularExpression` object which represents a regex pattern and provides various regex methods *(`match()`, `replace()`, `split()`)*.
- The `Builder` which provides a human-readable API for building regular expressions.
- The `Regex` static facade which provides a static interface for the `RegularExpression` object.

### Getting Started.

[](#getting-started)

To perform regex functions such as `match`, `replace`, `split`, we need to create a `RegularExpression` instance. There are various ways to do this.

```
use Tea\Regex\Regex;
use function Tea\Regex\re;
use Tea\Regex\RegularExpression;

// 1. Creating directly.
$regex = new RegularExpression('^\d+-([A-Za-z]+)-([A-Za-z]+)');
$matches = $regex->match('254-foo-bar-baz'); // 'Tea\Regex\Result\Matches' object

// 2. Using the Regex static facade.
$regex = Regex::create('^\d+'); // 'Tea\Regex\RegularExpression' object
$replaced = $regex->replace('x', '254-foo-bar-baz'); // 'Tea\Regex\Result\Replacement' object

// 3. Using the re() function.
$regex = re('-'); // 'Tea\Regex\RegularExpression' object
$result = $regex->split('254-foo-bar-baz'); // array('254', 'foo', 'bar', 'baz')

```

Notice that the delimiters and modifiers are missing from the regex patterns used above? Yes. The methods above will throw an error if you provide a pattern with the delimiters and/or any modifiers set. In the examples above, `/` is be used as the delimiter and the `u` modifiers is set. `/` delimiter and `u` modifier are the default.

To set the delimiter and modifiers to be used:

```
// Compiles to '#^ \d+ - ([A-Za-z]+) - ([A-Za-z]+)#ix'
$regex = new RegularExpression('^ \d+ - ([A-Za-z]+) - ([A-Za-z]+)', 'ix', '#');

// Compiles to '|^\d+|u'
$regex = Regex::create('^\d+', null, '|');

// Compiles to '/-/'
$regex = re('-', '', '/');

```

Creating with complete regex patterns.

```
$regex = RegularExpression::from('/^\d+/u');
Regex::from(...);
Regex::match(...);
Regex::replace(...);

```

### `Match`

[](#match)

...

### `MatchAll`

[](#matchall)

...

### `replace`

[](#replace)

...

### `replaceCallback`

[](#replacecallback)

...

### `filter`

[](#filter)

...

### `matches`

[](#matches)

...

### `replaced`

[](#replaced)

...

### `split`

[](#split)

...

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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://avatars.githubusercontent.com/u/1615382?v=4)[David Kyalo](/maintainers/davidkyalo)[@davidkyalo](https://github.com/davidkyalo)

---

Top Contributors

[![davidkyalo](https://avatars.githubusercontent.com/u/1615382?v=4)](https://github.com/davidkyalo "davidkyalo (60 commits)")

### Embed Badge

![Health badge](/badges/tea-regex/health.svg)

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

###  Alternatives

[demouth/dmgeocoder

Geocoding library.

216.9k](/packages/demouth-dmgeocoder)

PHPackages © 2026

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