gherkins/regexpbuilderphp
Composer 安装命令:
composer require gherkins/regexpbuilderphp
包简介
PHP port of thebinarysearchtree/regexpbuilderjs
README 文档
README
____ _____ ____ _ _ _ ____ _ _ ____
| _ \ ___ __ _| ____|_ ___ __ | __ ) _ _(_) | __| | ___ _ __| _ \| | | | _ \
| |_) / _ \/ _` | _| \ \/ / '_ \| _ \| | | | | |/ _` |/ _ \ '__| |_) | |_| | |_) |
| _ < __/ (_| | |___ > <| |_) | |_) | |_| | | | (_| | __/ | | __/| _ | __/
|_| \_\___|\__, |_____/_/\_\ .__/|____/ \__,_|_|_|\__,_|\___|_| |_| |_| |_|_|
|___/ |_|
human-readable regular expressions for PHP
PHP port of regexpbuilderjs
RegExpBuilder integrates regular expressions into the programming language, thereby making them easy to read and maintain. Regular Expressions are created by using chained methods and variables such as arrays or strings.
Installation
composer req gherkins/regexpbuilderphp
Or download the appropriate release and require RegExpBuilder.php and RegExp.php from /src.
Documentation
https://github.com/gherkins/regexpbuilderphp/wiki
Examples
use Gherkins\RegExpBuilderPHP; $builder = new RegExpBuilder();
Validation
$regExp = $builder ->startOfInput() ->exactly(4)->digits() ->then("_") ->exactly(2)->digits() ->then("_") ->min(3)->max(10)->letters() ->then(".") ->anyOf(array("png", "jpg", "gif")) ->endOfInput() ->getRegExp(); //true $regExp->matches("2020_10_hund.jpg"); $regExp->matches("2030_11_katze.png"); $regExp->matches("4000_99_maus.gif"); //false $regExp->matches("123_00_nein.gif"); $regExp->matches("4000_0_nein.pdf"); $regExp->matches("201505_nein.jpg");
Search
$regExp = $builder ->multiLine() ->globalMatch() ->min(1)->max(10)->anythingBut(" ") ->anyOf(array(".pdf", ".doc")) ->getRegExp(); $text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy SomeFile.pdf eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. doc_04.pdf Stet clita kasd File.doc.' $matches = $regExp->findIn($text); //true ($matches[0] === "SomeFile.pdf"); ($matches[1] === "doc_04.pdf"); ($matches[2] === "File.doc");
Replace
$regExp = $builder ->min(1) ->max(10) ->digits() ->getRegExp(); $text = "98 bottles of beer on the wall"; $text = $regExp->replace( $text, function ($match) { return (int)$match + 1; } ); //true ("99 bottles of beer on the wall" === $text);
Validation with multiple patterns
$a = $builder ->startOfInput() ->exactly(3)->digits() ->anyOf(array(".pdf", ".doc")) ->endOfInput(); $b = $builder ->getNew() ->startOfInput() ->exactly(4)->letters() ->then(".jpg") ->endOfInput(); $regExp = $builder ->getNew() ->eitherFind($a) ->orFind($b) ->getRegExp(); //true $regExp->matches("123.pdf"); $regExp->matches("456.doc"); $regExp->matches("bbbb.jpg"); $regExp->matches("aaaa.jpg"); //false $regExp->matches("1234.pdf"); $regExp->matches("123.gif"); $regExp->matches("aaaaa.jpg"); $regExp->matches("456.docx");
Take a look at the tests for more examples
gherkins/regexpbuilderphp 适用场景与选型建议
gherkins/regexpbuilderphp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 186.39k 次下载、GitHub Stars 达 1.35k, 最近一次更新时间为 2015 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「builder」 「regex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gherkins/regexpbuilderphp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gherkins/regexpbuilderphp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gherkins/regexpbuilderphp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Sphinx Query Builder extension for the Laravel Database package
Anax Database Active Record module for model classes.
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.
Convert Regular Expressions into text, for testing
Adds request-parameter validation to the SLIM 3.x PHP framework
统计信息
- 总下载量: 186.39k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1349
- 点击次数: 20
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-12