cawa0505/verbal-expressions-php

使PHP正则表达式变得简单。

v1.0.0 2019-04-06 22:24 UTC

This package is auto-updated.

Last update: 2024-09-07 10:01:42 UTC


README

Verbal Expressions 是一个PHP库,用于帮助构建复杂的正则表达式。

示例

$regex = new VerbalExpressions;

$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.", "-");

其他实现

您可以在 VerbalExpressions.github.io 上看到所有端口的最新列表。

构建项目和运行测试

所有测试都是使用PHPUnit编写的。请确保您已安装PHPUnit并在贡献之前运行所有测试。