PHPackages                             tstache/randexp - 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. tstache/randexp

ActiveLibrary

tstache/randexp
===============

randexp will generate a random string that matches a given regex

1.3(1y ago)42.7k↓32.1%1MITPHPPHP ^8.2

Since Dec 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/tstache/randexp)[ Packagist](https://packagist.org/packages/tstache/randexp)[ RSS](/packages/tstache-randexp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (1)

RandExp
=======

[](#randexp)

RandExp will generate a random string that matches a given regex.

It is based and inspired by the JS library .

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

[](#installation)

```
composer require tstache/randexp
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
include 'vendor/autoload.php';

$randExp = new \RandExp\RandExp('H[euioa]llo{1,10} (World|You)\n');
echo $randExp->generate();  // Output: Hellooooooo World
echo $randExp->generate();  // Output: Hullooooo You

$randExp = new \RandExp\RandExp('\d{4}');
echo $randExp->generate();  // Output: 2709
```

### More examples

[](#more-examples)

```
include 'vendor/autoload.php';

// Ignore-case option
$randExp = new \RandExp\RandExp('Hello', 'i');
echo $randExp->generate();  // Output: heLLO

// Capturing group reference
$randExp = new \RandExp\RandExp('\d{4}');
echo $randExp->generate();  // Output: 5851

// Maximum allowed repetition
$randExp = new \RandExp\RandExp('Hello*');
$randExp->maxRepetition = 2;
echo $randExp->generate();  // Output: Helloo

// Adding UTF-8 codepoints
$randExp = new \RandExp\RandExp('.{10}');
$randExp->charRange->add(127, 65535);
echo $randExp->generate(); // Output: Ꮻ啒窒녳ઠ椹䲀摷ꔞ
```

### Supported regex tokens

[](#supported-regex-tokens)

- `.`: Any character
- `^`: Position start
- `$`: Position end
- `\w`: Word
- `\W`: Not word
- `\d`: Int
- `\D`: Not int
- `\s`: Whitespace
- `\S`: Not whitespace
- `\b`: Word boundary
- `\B`: Non word boundary
- `\` followed by number: Capturing group reference
- `[` and `]`: Custom sets
- `(` and `)`: Capture group
- `|`: Choice
- `{` and `}`: Repetition range
- `?`: Repetition 0 or 1
- `+`: Repetition 1 or more
- `*`: Repetition 0 or more

Tests
-----

[](#tests)

Run tests via:

```
vendor/bin/phpunit
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance42

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~256 days

Total

4

Last Release

479d ago

PHP version history (2 changes)1.0PHP ^8.1

1.2PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/535b960dae1ca551ee0c4d4236cf774c1a5bc09919ef055af2d1af1c0bb86f50?d=identicon)[tstache](/maintainers/tstache)

---

Top Contributors

[![ts-mothership](https://avatars.githubusercontent.com/u/60600855?v=4)](https://github.com/ts-mothership "ts-mothership (5 commits)")[![tstache](https://avatars.githubusercontent.com/u/18681445?v=4)](https://github.com/tstache "tstache (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tstache-randexp/health.svg)

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

PHPackages © 2026

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