hexpress

hexpress is a PHP library that human way to define regular expressions

  • 所有者: sizuhiko/hexpress
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

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
主编程语言PHP
编程语言PHP (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2015-09-13 08:11:22
推送于2016-05-29 08:42:39
最后一次提交2016-05-29 17:42:38
发布数2
最新版本名称v0.1.1 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数41
关注者数4
派生数0
提交数52
已启用问题?
问题数0
打开的问题数0
拉请求数4
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?