icomefromthenet / reverse-regex
Convert Regular Expressions into text, for testing
Installs: 360 381
Dependents: 13
Suggesters: 1
Security: 0
Stars: 135
Watchers: 8
Forks: 38
Open Issues: 7
Requires
- php: ^7.1
- doctrine/common: ^2.8
- patchwork/utf8: >=1.3
Requires (Dev)
- phpunit/phpunit: ^7.0
README
Use Regular Expressions to generate text strings can be used in the following situations:
- Wrting 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
{ "require" : { "icomefromthenet/reverse-regex" : "dev-master" } }
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 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
.