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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?