PHPackages                             hoa-math-community/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. hoa-math-community/regex

ActiveLibrary

hoa-math-community/regex
========================

The Hoa\\Regex library.

v2.0.0(3y ago)01.1k↓25%11BSD-3-ClausePHPPHP ~8.0

Since Sep 16Pushed 3y agoCompare

[ Source](https://github.com/hoa-math-community/Regex)[ Packagist](https://packagist.org/packages/hoa-math-community/regex)[ RSS](/packages/hoa-math-community-regex/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (15)Used By (1)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/4518a3c9836151b11ac14f0394d85ef867d3547578274f4cdf7280921f462a20/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f72656765782f6d61737465722e737667)](https://travis-ci.org/hoaproject/regex) [![Code coverage](https://camo.githubusercontent.com/d156e8602614fad5c14f23ccc5ef4a6ec3eac3666b809c37940f86e999fb4298/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f72656765782f6d61737465722e737667)](https://coveralls.io/github/hoaproject/regex?branch=master) [![Packagist](https://camo.githubusercontent.com/e63f65d78d2697c5c6c96e7a9528bfc1838e3a694dd3e02b2de4c7dc953cf4ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f72656765782e737667)](https://packagist.org/packages/hoa/regex) [![License](https://camo.githubusercontent.com/924e1fdaea309e5dcb30642c3c9b32784c95d046c581526ca33a0b5531378cee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f72656765782e737667)](https://hoa-project.net/LICENSE)

 Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
 Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Regex
==========

[](#hoaregex)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Regex)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/regex)

This library provides tools to analyze regular expressions and generate strings based on regular expressions ([Perl Compatible Regular Expressions](http://pcre.org)).

[Learn more](https://central.hoa-project.net/Documentation/Library/Regex).

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

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/regex`](https://packagist.org/packages/hoa/regex):

```
$ composer require hoa/regex '~1.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

As a quick overview, we propose to see two examples. First, analyze a regular expression, i.e. lex, parse and produce an AST. Second, generate strings based on a regular expression by visiting its AST with an isotropic random approach.

### Analyze regular expressions

[](#analyze-regular-expressions)

We need the [`Hoa\Compiler`library](https://central.hoa-project.net/Resource/Library/Compiler) to lex, parse and produce an AST of the following regular expression: `ab(c|d){2,4}e?`. Thus:

```
// 1. Read the grammar.
$grammar  = new Hoa\File\Read('hoa://Library/Regex/Grammar.pp');

// 2. Load the compiler.
$compiler = Hoa\Compiler\Llk\Llk::load($grammar);

// 3. Lex, parse and produce the AST.
$ast      = $compiler->parse('ab(c|d){2,4}e?');

// 4. Dump the result.
$dump     = new Hoa\Compiler\Visitor\Dump();
echo $dump->visit($ast);

/**
 * Will output:
 *     >  #expression
 *     >  >  #concatenation
 *     >  >  >  token(literal, a)
 *     >  >  >  token(literal, b)
 *     >  >  >  #quantification
 *     >  >  >  >  #alternation
 *     >  >  >  >  >  token(literal, c)
 *     >  >  >  >  >  token(literal, d)
 *     >  >  >  >  token(n_to_m, {2,4})
 *     >  >  >  #quantification
 *     >  >  >  >  token(literal, e)
 *     >  >  >  >  token(zero_or_one, ?)
 */
```

We read that the whole expression is composed of a single concatenation of two tokens: `a` and `b`, followed by a quantification, followed by another quantification. The first quantification is an alternation of (a choice betwen) two tokens: `c` and `d`, between 2 to 4 times. The second quantification is the `e` token that can appear zero or one time.

We can visit the tree with the help of the [`Hoa\Visitor`library](https://central.hoa-project.net/Resource/Library/Visitor).

### Generate strings based on regular expressions

[](#generate-strings-based-on-regular-expressions)

To generate strings based on the AST of a regular expressions, we will use the `Hoa\Regex\Visitor\Isotropic` visitor:

```
$generator = new Hoa\Regex\Visitor\Isotropic(new Hoa\Math\Sampler\Random());
echo $generator->visit($ast);

/**
 * Could output:
 *     abdcde
 */
```

Strings are generated at random and match the given regular expression.

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

[](#documentation)

The [hack book of `Hoa\Regex`](https://central.hoa-project.net/Documentation/Library/Regex)contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 92.8% 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 ~231 days

Recently: every ~632 days

Total

14

Last Release

1244d ago

Major Versions

0.15.08.13 → 1.16.01.142016-01-14

1.17.01.13 → v2.0.02022-12-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/14144958f1893ddd81dafbd4df8583e38792ccc089462e3cb14b80eeba32cef3?d=identicon)[hubipe](/maintainers/hubipe)

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (128 commits)")[![Metalaka](https://avatars.githubusercontent.com/u/5406767?v=4)](https://github.com/Metalaka "Metalaka (3 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (2 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (1 commits)")[![turkanis](https://avatars.githubusercontent.com/u/1216968?v=4)](https://github.com/turkanis "turkanis (1 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (1 commits)")[![jubianchi](https://avatars.githubusercontent.com/u/327237?v=4)](https://github.com/jubianchi "jubianchi (1 commits)")[![hubipe](https://avatars.githubusercontent.com/u/617880?v=4)](https://github.com/hubipe "hubipe (1 commits)")

---

Tags

libraryregexcompiler

### Embed Badge

![Health badge](/badges/hoa-math-community-regex/health.svg)

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

###  Alternatives

[filp/whoops

php error handling for cool kids

13.2k402.4M1.4k](/packages/filp-whoops)[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[composer/pcre

PCRE wrapping library that offers type-safe preg\_\* replacements.

693313.8M34](/packages/composer-pcre)[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)[league/iso3166

ISO 3166-1 PHP Library

69536.3M116](/packages/league-iso3166)

PHPackages © 2026

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