Download the PHP package s9e/regexp-builder-command without Composer
On this page you can find all versions of the php package s9e/regexp-builder-command. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download s9e/regexp-builder-command
More information about s9e/regexp-builder-command
Files in s9e/regexp-builder-command
Package regexp-builder-command
Short Description Console command that generates a regexp from a list of strings.
License MIT
Homepage https://github.com/s9e/RegexpBuilderCommand/
Informations about the package regexp-builder-command
Synopsis
build-regexp
is a command line tool that generates regular expressions that match a given set of strings.
Installation
There are two ways to use this command. You can download the latest release as a PHAR:
Or you can install the command as a Composer dependency:
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:
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:
Alternatively, the list of strings can be passed as a JSON array:
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:
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
andpcre2
escape non-printing characters and characters outside of low ASCII using PCRE's escape sequences\xhh
and\x{hh..}
. If theu
flag is specified, the regexp operates on Unicode codepoints. Otherwise, it operates on bytes.java
andre2
are functionally equivalent topcre2
and always operate on Unicode codepoints.javascript
escapes non-printing characters and characters outside of low ASCII as\xhh
,\uhhhh
, and\u{hhhhh}
. If theu
flag is not present, characters outside the BMP are split into surrogate pairs.raw
does not escape any literals. If theu
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.
Maintenance
To generate build-regexp.phar
you'll need to download a recent release of box.phar
and save it to the bin
directory, then run composer build-phar
.
See also
- https://github.com/s9e/RegexpBuilder - The library that powers this tool.
- https://github.com/devongovett/regexgen - Similar tool written in JavaScript.
- https://github.com/pemistahl/grex - Similar tool written in Rust.