PHPackages                             mezatech/paggern - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. mezatech/paggern

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

mezatech/paggern
================

Pattern interpreter for generating random strings.

0.1.1(12y ago)07BSD-3-ClausePHPPHP &gt;=5.4

Since Apr 17Pushed 11y ago1 watchersCompare

[ Source](https://github.com/MezaTech/paggern)[ Packagist](https://packagist.org/packages/mezatech/paggern)[ Docs](https://github.com/gajus/parsley)[ RSS](/packages/mezatech-paggern/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Paggern
=======

[](#paggern)

[![Build Status](https://camo.githubusercontent.com/ccd2afbe45a04f93b3b22eea3a56d2d6397ae8c1d09fbd88b004c4374587faf2/68747470733a2f2f7472617669732d63692e6f72672f67616a75732f7061676765726e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/gajus/paggern)[![Coverage Status](https://camo.githubusercontent.com/72d0306a35c08537fccecdb80287daa7e1026fbb939b94c9933e0ee09b08b40d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f67616a75732f7061676765726e2f62616467652e706e673f6272616e63683d6d61737465722663616368653d313233)](https://coveralls.io/r/gajus/paggern?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/30237d1c3f7cc2fedf5cc1a92ff34ca5185e41480d537f2b61877a089ddb0f12/68747470733a2f2f706f7365722e707567782e6f72672f67616a75732f7061676765726e2f76657273696f6e2e706e67)](https://packagist.org/packages/gajus/paggern)[![License](https://camo.githubusercontent.com/3d9462b7636d9e5f63cf031f29e18667a7e80453b94c9402bc153af35b76c4bd/68747470733a2f2f706f7365722e707567782e6f72672f67616a75732f7061676765726e2f6c6963656e73652e706e67)](https://packagist.org/packages/gajus/paggern)

Pattern interpreter for generating random strings.

Generator
---------

[](#generator)

```
$generator = new \Gajus\Paggern\Generator();

/**
 * Generate a set of random codes based on Paggern pattern.
 * Codes are guaranteed to be unique within the set.
 *
 * @param string $pattern Paggern pattern.
 * @param int $amount Number of codes to generate.
 * @param int $safeguard Number of additional codes generated in case there are duplicates that need to be replaced.
 * @return array
 */
$codes = $generator->generateFromPattern('FOO[A-Z]{10}[0-9]{2}', 100);
```

The above example will generate an array containing 100 codes, each prefixed with "FOO", followed by 10 characters from "ABCDEFGHKMNOPRSTUVWXYZ23456789" haystack and 2 numbers from "0123456789" haystack.

Paggern utilises [RandomLib](https://github.com/ircmaxell/RandomLib) to generate the pattern matching random character pool.

Lexer
-----

[](#lexer)

Lexer exposes a method to tokenise the string. `Lexer` is independant of the `Generator`. You can choose to interpret `Lexer` tokens using your own implementation of the `Generator`.

```
$lexer = new \Gajus\Paggern\Lexer();

/**
 * Tokeniser explodes input into components describing the properties expressed in the pattern.
 *
 * @param string $pattern
 * @param boolean $expand Augment token definition with the haystack of possible values.
 * @return array
 */
$lexer->tokenise('[a-c]{3}[1-3]{3}', true);
```

```
[
    [
        'type' => 'range',
        'token' => 'a-c',
        'repetition' => 3,
        'haystack' => 'abc'
    ],
    [
        'type' => 'range',
        'token' => '1-3',
        'repetition' => 3,
        'haystack' => 123
    ]
]
```

### Supported Tokens

[](#supported-tokens)

#### Literal

[](#literal)

Pattern can consist of literal characters, e.g. prefix of suffix of the code.

```
$lexer->tokenise('abc');
```

```
[
    [
        'type' => 'literal',
        'string' => 'abc'
    ]
]
```

The above pattern commands that the string is literally "abc".

#### Range

[](#range)

Range can be either numeric or ASCII.

```
$lexer->tokenise('[a-z]');
```

In the `[a-z]` example, string must be a character from "abcdefghijklmnopqrstuvwxyz" haystack.

```
[
    [
        'type' => 'range',
        'token' => 'a-z',
        'repetition' => 1
    ]
]
```

#### Range with Repetition

[](#range-with-repetition)

If the character must occur more than once, use repetition.

```
$lexer->tokenise('[a-c]{3}');
```

In the `[a-z]{3}` example, string must consist of 3 characters from the "abc" haystack.

```
[
    [
        'type' => 'range',
        'token' => 'a-c',
        'repetition' => 3
    ]
]
```

#### Character Classes

[](#character-classes)

Predefined character classes can be used instead of ranges.

Character ClassRange`\U`"ABCDEFGHKMNOPRSTUVWXYZ23456789" (or A-Z0-9 excluding IJLQ01) describes characters that are unambiguously recognised regardless of the font or case-sensitivity. The designated use case is voucher codes.#### Character Classes with Repetition

[](#character-classes-with-repetition)

Similar to the Range with Repetition, Character Classes can be used with repetition, e.g.

```
$lexer->tokenise('\U{3}');
```

Limitations
-----------

[](#limitations)

- Pattern cannot include `[]{}` characters.
- Pattern cannot include characters outside of the ASCII.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

4414d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a7c17b25848bf9ad789ff5115159cd996cba6d0ed36f5fdbbcebe05c81beddc?d=identicon)[AmrSoliman](/maintainers/AmrSoliman)

---

Top Contributors

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

---

Tags

codeparsergeneratorvoucher

### Embed Badge

![Health badge](/badges/mezatech-paggern/health.svg)

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

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k902.6M1.8k](/packages/nikic-php-parser)[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k910.8M118](/packages/doctrine-lexer)[erusev/parsedown

Parser for Markdown.

15.0k151.8M732](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

3.0k404.0M702](/packages/league-commonmark)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)

PHPackages © 2026

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