ilario-pierbattista / reverse-regex
Convert Regular Expressions into text, for testing. Fork of icomefromthenet/reverse-regex
Package info
github.com/ilario-pierbattista/ReverseRegex
pkg:composer/ilario-pierbattista/reverse-regex
0.8.0
2026-10-11 20:07 UTC
Requires
- php: ^8.1
- doctrine/collections: ^1.6.5 || ^2 || ^3
- doctrine/lexer: ^1.2.1 || ^2 || ^3
- symfony/polyfill-mbstring: ^1.20.0
Requires (Dev)
- facile-it/facile-coding-standard: 1.5.0
- friendsofphp/php-cs-fixer: 3.95.27
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
Replaces
None
- dev-master
- 0.8.0
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.1
- 0.3.0
- v0.2.0.0
- v0.1.0.0
- v0.0.6.3
- v0.0.6.2
- v0.0.6.1
- v0.0.6
- v0.0.5
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-claude/project-thread-id04e5
- dev-claude/project-thread-rtydmt-psalm
- dev-claude/project-thread-rtydmt
- dev-claude/dependabot
- dev-claude/parser-null-head
- dev-claude/release-automation
- dev-claude/examples-ci
- dev-claude/readme
- dev-claude/phpstan
- dev-claude/types
- dev-claude/strict-types
- dev-claude/psr4-tests
- dev-claude/project-thread-285ny0
- dev-claude/project-thread-9mdffo-parser-tests
- dev-claude/project-thread-9mdffo-actions-v6
- dev-claude/project-thread-9mdffo-actions
- dev-claude/project-thread-9mdffo-codecov
- dev-claude/project-thread-9mdffo-tests
- dev-claude/project-thread-9mdffo
- dev-claude/project-thread-h79rj4
- dev-claude/project-thread-th68ns
- dev-claude/project-thread-axibk8
- dev-2510_unbound_generator
- dev-2212_php8
- dev-2210_update_composer_dependencies
This package is auto-updated.
Last update: 2026-10-11 20:14:54 UTC
README
This is a fork of https://github.com/icomefromthenet/ReverseRegex (that provides
icomefromthenet/reverse-regex).
Use regular expressions to generate text strings. It can be used in the following situations:
- Writing test data for web forms.
- Writing test data for databases.
- Generating test data for regular expressions.
Example
use ReverseRegex\Lexer; use ReverseRegex\Random\SimpleRandom; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; # load composer require "vendor/autoload.php"; $lexer = new Lexer('[a-z]{10}'); $gen = new SimpleRandom(10007); $result = ''; $parser = new Parser($lexer,new Scope(),new Scope()); $parser->parse()->getResult()->generate($result,$gen); echo $result;
Produces
jmceohykoa
aclohnotga
jqegzuklcv
ixdbpbgpkl
kcyrxqqfyw
jcxsjrtrqb
kvaczmawlz
itwrowxfxh
auinmymonl
dujyzuhoag
vaygybwkfm
Other examples
Installing
To install use composer
composer require ilario-pierbattista/reverse-regex
Writing a Regex
- Escape all meta-characters i.e. if you need to escape the character in a regex you will need to escape here.
- Not all meta-characters are supported, see the list below. Negated character classes (
[^a-z]),\pand\Pare rejected with an exception. - Use
\X{####}to specify unicode value use[\X{####}-\X{####}]to specify range. - Unicode properties (
\p,\P) are not supported, because there is no PHP port of the UCD. - Quantifiers are applied to left most group, literal or character class.
- The
+and*quantifiers repeat at most 100 times by default; change it with$parser->setUnboundedMax($n).
Regex Support
| Example | Description | Resulting String |
|---|---|---|
| (abcf) | Support literals this would generate string | `abcf` |
| \((abcf)\) | Escape meta characters as you normally would in a regex | `(abcf)` |
| [a-z] | Character Classes are supported | `a` |
| a{5} | Quantifiers supported always last group or literal or character class | `aaaaa` |
| a{1,5} | Range Quantifiers supported | `aa` |
| a|b|c | Alternation supported pick one of three at random | `b` |
| a|(y|d){5} | Groups supported with alternation and quantifiers | `ddddd` or `a` or `yyyyy` |
| \d | Digit shorthand equ [0-9] | `1` |
| \w | word character shorthand equ [a-zA-Z0-9_] | `j` |
| \W | Non word character shorthand equ [^a-zA-Z0-9_] | `j` |
| \s | White space shorthand ASCII only | ` ` |
| \S | Non White space shorthand ASCII only | `i` |
| . | Dot all ASCII characters | `$` |
| * + ? | Short hand quantifiers, not recommended | |
| \X{00FF}[\X{00FF}-\X{00FF}] | Unicode ranges | |
| \xFF[\xFF-\xFF] | Hex ranges |