ahorkh / reverse-regex
Convert Regular Expressions into text, for testing
Installs: 1 748
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 38
Open Issues: 0
Requires
- php: >=7.2
- doctrine/collections: ^1.6
- doctrine/lexer: ^1.2
- symfony/polyfill-mbstring: ^1.23
Requires (Dev)
README
Use Regular Expressions to generate strings.
Installation
This library is installed via Composer. To install, use composer require pointybeard/reverse-regex
in your application.
Usage
<?php declare(strict_types=1); use ReverseRegex\Lexer; use ReverseRegex\Random\SimpleRandom; use ReverseRegex\Parser; use ReverseRegex\Generator\Scope; require "vendor/autoload.php"; $pattern = "[a-z0-9]{10}"; // 10 random letters and numbers $lexer = new Lexer($pattern); $random = new SimpleRandom(); $parser = new Parser($lexer, new Scope(), new Scope()); $generator = $parser->parse()->getResult(); $result = ''; $parser = new Parser($lexer,new Scope(),new Scope()); var_dump($generator->generate($result, $random)); // string(10) "j2ydisgoks"
See https://github.com/pointybeard-forks/ReverseRegex/tree/master/examples for more examples.
Notes When Writing Regular Expressions
- 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 suppported see list below.
- Use
\X{####}
to specify unicode value use[\X{####}-\X{####}]
to specify range. - Unicdoe
\p
not supported, I could not find a port of UCD to php, maybe in the future support be added. - Quantifiers are applied to left most group, literal or character class.
- Beware of the
+
and*
quantifers they apply a possible maxium number of occurances up toPHP_INT_MAX
.
Supported Syntax
About
Requirements
- This library works with PHP 7.2 or above.
Support
If you believe you have found a bug, please report it using the GitHub issue tracker.
Author
- Lewis Dyer (http://www.icomefromthenet.com, https://github.com/icomefromthenet/ReverseRegex) - Original author
- Alannah Kearney (https://github.com/pointybeard) - Fixed a few things after library was abandoned
- See also the list of contributors who participated in this project
License
"ReverseRegex" is released under the MIT License. See LICENCE for details.