PHPackages                             s9e/regexp-builder-command - 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. [CLI &amp; Console](/categories/cli)
4. /
5. s9e/regexp-builder-command

ActiveLibrary[CLI &amp; Console](/categories/cli)

s9e/regexp-builder-command
==========================

Console command that generates a regexp from a list of strings.

1.0.0(8mo ago)11301[1 issues](https://github.com/s9e/RegexpBuilderCommand/issues)MITPHPPHP &gt;=8.1CI passing

Since Feb 7Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/s9e/RegexpBuilderCommand)[ Packagist](https://packagist.org/packages/s9e/regexp-builder-command)[ Docs](https://github.com/s9e/RegexpBuilderCommand/)[ RSS](/packages/s9e-regexp-builder-command/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (17)Used By (0)

### Synopsis

[](#synopsis)

`build-regexp` is a command line tool that generates regular expressions that match a given set of strings.

### Installation

[](#installation)

There are two ways to use this command. You can download the [latest release as a PHAR](https://github.com/s9e/RegexpBuilderCommand/releases/latest/download/build-regexp.phar):

```
$ wget -q https://github.com/s9e/RegexpBuilderCommand/releases/latest/download/build-regexp.phar
$ chmod +x build-regexp.phar
$ ./build-regexp.phar --version
build-regexp 1.0.0

```

Or you can install the command as a [Composer](https://getcomposer.org/download/) dependency:

```
$ composer -q require s9e/regexp-builder-command
$ vendor/bin/build-regexp --version
build-regexp 1.0.0

```

### Usage

[](#usage)

Strings can be specified either directly in the command invocation or via an input file. The following shell example shows how to pass them in the command invocation as a space-separated list:

```
$ ./build-regexp.phar foo bar baz
ba[rz]|foo

```

In the following example, we create a file with each value on its own line, then we pass the name of the file via the `infile` option:

```
$ echo -e "one\ntwo\nthree" > strings.txt
$ ./build-regexp.phar --infile strings.txt
one|t(?:hree|wo)

```

Alternatively, the list of strings can be passed as a JSON array:

```
$ echo '["foo","bar"]' > strings.json
$ ./build-regexp.phar --infile strings.json --infile-format json
bar|foo

```

By default, the result is output in the terminal directly. Alternatively, it can be saved to a file specified via the `outfile` option. In the following example, we save the result to a `out.txt` file before checking its content:

```
$ ./build-regexp.phar --outfile out.txt foo bar baz
$ cat out.txt
ba[rz]|foo

```

### Presets

[](#presets)

Several presets are available to generate regexps for different engines. They determine how the input is interpreted, and how/which characters are escaped in the output. The following presets are available:

- `pcre` and `pcre2` escape non-printing characters and characters outside of low ASCII using [PCRE's escape sequences](https://www.pcre.org/current/doc/html/pcre2syntax.html#SEC3) `\xhh` and `\x{hh..}`. If the `u` flag is specified, the regexp operates on Unicode codepoints. Otherwise, it operates on bytes.
- `java` and `re2` are functionally equivalent to `pcre2` and always operate on Unicode codepoints.
- `javascript` escapes non-printing characters and characters outside of low ASCII as `\xhh`, `\uhhhh`, and `\u{hhhhh}`. If the `u` flag is not present, characters outside the BMP are split into surrogate pairs.
- `raw` does not escape any literals. If the `u` flag is specified, the regexp operates on Unicode codepoints. Otherwise, it operates on bytes and is not guaranteed to produce a UTF-8 string.

The following examples show the results of a few different presets with the Unicode characters U+1F601 and U+1F602 as input.

```
$ ./build-regexp.phar --preset pcre "😁" "😂"
\xF0\x9F\x98[\x81\x82]

$ ./build-regexp.phar --preset javascript "😁" "😂"
\uD83D[\uDE01\uDE02]

$ ./build-regexp.phar --preset pcre --flags u "😁" "😂"
[\x{1F601}\x{1F602}]

$ ./build-regexp.phar --preset javascript --flags u "😁" "😂"
[\u{1F601}\u{1F602}]

```

### Maintenance

[](#maintenance)

To generate `build-regexp.phar` you'll need to [download a recent release](https://github.com/box-project/box/releases) of `box.phar` and save it to the `bin` directory, then run `composer build-phar`.

### See also

[](#see-also)

-  - The library that powers this tool.
-  - Similar tool written in JavaScript.
-  - Similar tool written in Rust.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance57

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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 ~99 days

Recently: every ~276 days

Total

14

Last Release

263d ago

Major Versions

0.5.4 → 1.0.02025-08-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/06ce60f935a636cbb13d7ca4733fa28c9a2c9d500834c6481f86e05fd4a55e86?d=identicon)[s9e](/maintainers/s9e)

---

Top Contributors

[![JoshyPHP](https://avatars.githubusercontent.com/u/317712?v=4)](https://github.com/JoshyPHP "JoshyPHP (43 commits)")

---

Tags

cliregexp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/s9e-regexp-builder-command/health.svg)

```
[![Health](https://phpackages.com/badges/s9e-regexp-builder-command/health.svg)](https://phpackages.com/packages/s9e-regexp-builder-command)
```

###  Alternatives

[nunomaduro/collision

Cli error handling for console/command-line PHP applications.

4.6k331.8M8.5k](/packages/nunomaduro-collision)[nunomaduro/termwind

It's like Tailwind CSS, but for the console.

2.5k239.8M286](/packages/nunomaduro-termwind)[helhum/typo3-console

A reliable and powerful command line interface for TYPO3 CMS

2939.0M192](/packages/helhum-typo3-console)[buggregator/trap

A simple and powerful tool for debugging PHP applications.

2591.7M40](/packages/buggregator-trap)[laminas/laminas-cli

Command-line interface for Laminas projects

563.7M54](/packages/laminas-laminas-cli)[phpcr/phpcr-utils

PHP Content Repository implementation independant utilities

743.2M14](/packages/phpcr-phpcr-utils)

PHPackages © 2026

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