koca/easyregex
Composer 安装命令:
composer require koca/easyregex
包简介
PHP Regular expressions made easy
关键字:
README 文档
README
- ported from VerbalExpressions
EasyRegex is a PHP library that helps to construct hard regular expressions.
Install
$ composer require koca/easyregex
Usage
// some tests use Koca\EasyRegex\EasyRegex; $regex = new EasyRegex; $regex ->startOfLine() ->then("http") ->maybe("s") ->then("://") ->maybe("www.") ->anythingBut(" ") ->endOfLine(); if($regex->test("https://github.com/")) echo "valid url"; else echo "invalid url"; if (preg_match($regex, 'http://github.com')) { echo 'valid url'; } else { echo 'invalid url'; } echo "<pre>". $regex->getRegex() ."</pre>"; echo $regex ->clean(array("modifiers" => "m", "replaceLimit" => 4)) ->find(' ') ->replace("This is a small test http://somesite.com and some more text.", "-");
Regex Capturing
$regex->find("You have ") ->beginCapture("count") ->word() ->endCapture(); $contributions = $regex->match("You have 258 contributions in the last year"); echo $contributions["count"]; // Output: 258
##Methods list
| Name | Description | Usage |
|---|---|---|
| add | add values to the expression | add('abc') |
| startOfLine | mark expression with ^ | startOfLine(false) |
| endoOfLine | mark the expression with $ | endOfLine() |
| then | add a string to the expression | add('foo') |
| find | alias for then | find('foo') |
| maybe | define a string that might appear once or not | maybe('.com') |
| anything | accept any string | anything() |
| anythingUntil | Anything up until given sequence of characters | anythingUntil('.com') |
| anythingBut | accept any string but the specified char | anythingBut(',') |
| something | accept any non-empty string | something() |
| somethingBut | anything non-empty except for these chars | somethingBut('a') |
| replace | shorthand for preg_replace() | replace($source, $val) |
| lineBreak | match \r \n | lineBreak() |
| br | shorthand for lineBreak | br() |
| tab | match tabs \t | tab() |
| word | match \w+ | word() |
| anyOf | any of the listed chars | anyOf('abc') |
| any | shorthand for anyOf | any('abc') |
| range | adds a range to the expression | range(a,z,0,9) |
| withAnyCase | match case default case sensitive | withAnyCase() |
| beginCapture | Capture groups (can optionally name) | beginCapture("bar") |
| endCapture | Stop capture | endCapture() |
| match | Shorthand method for preg_match | match("long string") |
| matchAll | Shorthand method for preg_match_all | matchAll("long string") |
| stopAtFirst | toggles the g modifiers | stopAtFirst() |
| addModifier | add a modifier | addModifier('g') |
| removeModifier | remove a mofier | removeModifier('g') |
| searchOneLine | Toggles m modifier | searchOneLine() |
| multiple | adds the multiple modifier | multiple('*') |
| _or | wraps the expression in an or with the provided value |
_or('bar') |
| limit | adds char limit | limit(1,3) |
| test | performs a preg_match | test('valid@email.com') |
Building the project and running the tests
The project supports Composer so you have to install Composer first before project setup.
curl -sS https://getcomposer.org/installer | php
php composer.phar install --dev
ln -s vendor/phpunit/phpunit/phpunit.php phpunit
./phpunit
License
This project is free and open source software, distributed under the MIT License
koca/easyregex 适用场景与选型建议
koca/easyregex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45 次下载、GitHub Stars 达 11, 最近一次更新时间为 2016 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「regex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 koca/easyregex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 koca/easyregex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 koca/easyregex 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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
A PHP port of https://github.com/francisrstokes/super-expressive
Very simple Form Input Validation for when you want to use your own existing forms.
统计信息
- 总下载量: 45
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-29