ahorkh/reverse-regex
Composer 安装命令:
composer require --dev ahorkh/reverse-regex
包简介
Convert Regular Expressions into text, for testing
README 文档
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
\pnot 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
| 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', '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, recommend not use them | |
\X{00FF}[\X{00FF}-\X{00FF}] |
Unicode ranges | |
\xFF[\xFF-\xFF] |
Hex ranges |
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.
ahorkh/reverse-regex 适用场景与选型建议
ahorkh/reverse-regex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.67k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「testing」 「regex」 「test data」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ahorkh/reverse-regex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ahorkh/reverse-regex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ahorkh/reverse-regex 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Testing Suite For Lumen like Laravel does.
Advanced TYPO3 redirect management for sys_redirect with regex and host/language-aware matching, CSV/.htaccess import/export, categories and priority, automatic slug redirect workflows, plus hit/log analytics.
Adds PHP's preg_replace function as a Twig filter.
The PHP SDK for Checkmango
Adds request-parameter validation to the SLIM 3.x PHP framework
统计信息
- 总下载量: 2.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-06