PHPackages                             xp-lang/php-pattern-operator - 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. xp-lang/php-pattern-operator

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

xp-lang/php-pattern-operator
============================

Pattern operator for PHP

v0.2.0(2y ago)03BSD-3-ClausePHPPHP &gt;=7.4.0

Since Jan 29Pushed 1y ago2 watchersCompare

[ Source](https://github.com/xp-lang/php-pattern-operator)[ Packagist](https://packagist.org/packages/xp-lang/php-pattern-operator)[ Docs](http://xp-framework.net/)[ RSS](/packages/xp-lang-php-pattern-operator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Pattern operator for PHP
========================

[](#pattern-operator-for-php)

[![Build status on GitHub](https://github.com/xp-lang/php-pattern-operator/workflows/Tests/badge.svg)](https://github.com/xp-lang/php-pattern-operator/actions)[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/8d36c648324906bf26eb6f6f608dcba958f42d9c766ab7a82cb14b9b25c736ab/68747470733a2f2f706f7365722e707567782e6f72672f78702d6c616e672f7068702d7061747465726e2d6f70657261746f722f76657273696f6e2e737667)](https://packagpatternt.org/packages/xp-lang/php-pattern-operator)

Plugin for the [XP Compiler](https://github.com/xp-framework/compiler/) which adds an `~` infix operator to the PHP language.

Examples
--------

[](#examples)

The pattern operator treats the following expression as a regular expression and returns the matches it generates:

```
if ($greeting ~ '/^H[ea]llo/') {
  // Matches!
}

if ($matches= $greeting ~ '/^H[ea]llo/') {
  // Work with $matches
}
```

The pattern is passed to [preg\_match](https://www.php.net/preg_match), so the above is equivalent of writing the following:

```
if (preg_match($greeting, '/^H[ea]llo/')) {
  // Matches!
}

if (preg_match($greeting, '/^H[ea]llo/', $matches)) {
  // Work with $matches
}
```

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

[](#installation)

After installing the XP Compiler into your project, also include this plugin.

```
$ composer require xp-framework/compiler
# ...

$ composer require xp-lang/php-pattern-operator
# ...
```

No further action is required.

See also
--------

[](#see-also)

- [xp-framework/compiler#130](https://github.com/xp-framework/compiler/issues/130) Motivation
-
-
- [https://puppet.com/docs/puppet/latest/lang\_expressions.html](https://puppet.com/docs/puppet/latest/lang_expressions.html) (`=~` and `!~`)
-  and
-  (PHP internals discussion, 2003)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

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.

###  Release Activity

Cadence

Every ~785 days

Total

2

Last Release

782d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.0.0

v0.2.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07d18d882c8b4aaf3466432f64018214f2771eda333202175431ee7233795376?d=identicon)[thekid](/maintainers/thekid)

---

Top Contributors

[![thekid](https://avatars.githubusercontent.com/u/696742?v=4)](https://github.com/thekid "thekid (20 commits)")

---

Tags

languagemodulexp

### Embed Badge

![Health badge](/badges/xp-lang-php-pattern-operator/health.svg)

```
[![Health](https://phpackages.com/badges/xp-lang-php-pattern-operator/health.svg)](https://phpackages.com/packages/xp-lang-php-pattern-operator)
```

PHPackages © 2026

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