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

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

robinbressan/regex-parser
=========================

AST for PCRE Regex

2414.3k↓33.3%4PHP

Since Nov 3Pushed 10y ago3 watchersCompare

[ Source](https://github.com/RobinBressan/regex-parser)[ Packagist](https://packagist.org/packages/robinbressan/regex-parser)[ RSS](/packages/robinbressan-regex-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

RegexParser
===========

[](#regexparser)

RegexParser is a parser for PCRE regex. It produces an AST which represents your regex. It can help you generating some inputs which match your regex.

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

[](#installation)

It is available with [Composer](http://getcomposer.org):

```
composer install robinbressan/regex-parser

```

Usage
-----

[](#usage)

To build an AST you need to create a parser:

```
$parser = \RegexParser\Parser\Parser::create();

$ast = $parser->parse('YOUR_REGEX');
```

You can now use a formatter to convert the AST to several format (only XML is supported today):

```
$formatter = new \RegexParser\Parser\Formatter\XMLFormatter();

$xml = $formatter->format($ast); // $xml is now an instance of DOMDocument
```

If you wish you can display it easily:

```
$xml->formatOutput = true;
echo $xml->saveXML();
```

Because you can get a DOMDocument, you are able to use XPath engine to query your AST.

Example
-------

[](#example)

The regex `^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$` will produce the following AST:

```

        _

          a
          z

          0
          9

        -

      .

          _

            a
            z

            0
            9

          -

  @

        a
        z

        0
        9

      -

      .

            a
            z

            0
            9

          -

      .

            a
            z

```

Generator
---------

[](#generator)

You can also create a generator based on your AST which will generate a string that match your regex:

```
$generator = new \RegexParser\Generator\RandomGenerator($ast);
$generator->generate($seed = null);
```

If you wish you can also create directly the generator :

```
$generator = new \RegexParser\Generator\RandomGenerator::create('YOUR_REGEX');
$generator->generate($seed = null);
```

Test
----

[](#test)

To run the test you must run `phpunit` command.

Contributing
------------

[](#contributing)

All contributions are welcome. If you add a new feature, ensure all tests are green!

License
-------

[](#license)

This application is available under the MIT License.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.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://avatars.githubusercontent.com/u/4641116?v=4)[Robin Bressan](/maintainers/RobinBressan)[@RobinBressan](https://github.com/RobinBressan)

---

Top Contributors

[![RobinBressan](https://avatars.githubusercontent.com/u/4641116?v=4)](https://github.com/RobinBressan "RobinBressan (25 commits)")[![EmanueleMinotto](https://avatars.githubusercontent.com/u/417201?v=4)](https://github.com/EmanueleMinotto "EmanueleMinotto (6 commits)")[![jpetitcolas](https://avatars.githubusercontent.com/u/688373?v=4)](https://github.com/jpetitcolas "jpetitcolas (1 commits)")

### Embed Badge

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

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

###  Alternatives

[digilist/snakedumper

5045.5k](/packages/digilist-snakedumper)

PHPackages © 2026

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