sizuhiko/hexpress
Composer 安装命令:
composer require sizuhiko/hexpress
包简介
hexpress is a PHP library that human way to define regular expressions
README 文档
README
hexpress
hexpress is a PHP library that human way to define regular expressions
hexpress is ported from Ruby's hexpress.
The hexpress is another take at the concept of "Verbal Hexpressions".
hexpress requires PHP >= 5.5
Using
use Hexpress\Hexpress; $pattern = (new Hexpress()) ->start("http") ->maybe("s") ->with("://") ->maybe(function($hex) { $hex->words()->with("."); }) ->find(function($hex) { $hex->matching(function($hex) {$hex->word()->with("-");})->many(); }) ->has(".") ->either(["com", "org"]) ->maybe("/") ->ending();
After use Hexpress\Hexpress you'll have access to the Hexpress class, which allows you to chain methods to build up a regex pattern.
You can see this pattern by calling either Hexpress#__toString() or Hexpress#toRegExp:
echo $pattern; #=> "^https?\:\/\/(?:(?:\w)+\.)?([\w\-]+)\.(?:com|org)\/?$" echo $pattern->toRegExp(); #=> "/^https?\:\/\/(?:(?:\w)+\.)?([\w\-]+)\.(?:com|org)\/?$/"
You can even do advanced composure of multiple patterns:
$protocol = (new Hexpress())->start("http")->maybe("s")->with("://"); $tld = (new Hexpress())->with(".")->either(["org", "com", "net"]); $link = (new Hexpress())->has($protocol)->find(function($hex) {$hex->words();})->including($tld); echo $link; #=> "^https?\:\/\/((?:\w)+)\.(?:org|com|net)"
Hexpressions are very flexible.
TODO
- PHP Document and API reference
- lookahead assertions
- lookbehind assertions
- back reference
- conditional subpattern
- once-only subpattern
- Internal option setting
Installing
Add this line to your application's composer.json:
"require": { "sizuhiko/hexpress": ">=1.0" },
And then execute:
$ composer install
Or install it yourself as:
$ composer require "sizuhiko/hexpress:>=1.0"
Contributing to this Library
Please feel free to contribute to the library with new issues, requests, unit tests and code fixes or new features. If you want to contribute some code, create a feature branch from develop, and send us your pull request.
sizuhiko/hexpress 适用场景与选型建议
sizuhiko/hexpress 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 309 次下载、GitHub Stars 达 41, 最近一次更新时间为 2015 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 sizuhiko/hexpress 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sizuhiko/hexpress 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 309
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 41
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-21