chevere/regex

有效的正则表达式

1.0.1 2024-01-08 12:27 UTC

This package is auto-updated.

Last update: 2024-09-20 12:00:11 UTC


README

🔔 订阅时事通讯,不错过任何关于Chevere的更新。

Chevere

Build Code size Apache-2.0 PHPStan Mutation testing badge

Quality Gate Status Maintainability Rating Reliability Rating Security Rating Coverage Technical Debt CodeFactor

摘要

Regex 允许使用经过验证的正则表达式

安装

Regex 通过包管理器和仓库源chevere/regex提供。

composer require chevere/regex

创建 Regex

通过传递正则表达式模式来创建 Regex。

use Chevere\Regex\Regex;

$regex = new Regex('/^Hello World!$/');

读取模式

现状

使用 __toString 方法访问实例创建时传递的模式。

$string = $regex->__toString();
// /^Hello World!$/

无分隔符

使用 noDelimiters 方法访问不带分隔符的正则表达式模式。

$string = $regex->noDelimiters();
// ^Hello World!$

无分隔符和锚点

使用 noDelimitersNoAnchors 方法访问不带分隔符和锚点的正则表达式模式。

$string = $regex->noDelimitersNoAnchors();
// Hello World!

匹配

match 方法提供 preg_match

$array = $regex->match('Hello World!');
// [Hello World!]

匹配所有

matchAll 方法提供 preg_match_all

$regex->matchAll();
// [Hello World!]

断言匹配

assertMatch 方法断言字符串匹配。当断言失败时抛出 Exceptions\NoMatchException

$regex->assertMatch('Hello World!');

断言匹配所有

assertMatchAll 方法断言字符串匹配所有。当断言失败时抛出 Exceptions\NoMatchException

$regex->assertMatchAll('Hello World!');

文档

文档可在chevere.org找到。

许可

版权 2024 Rodolfo Berrios A.

Chevere 依据 Apache 许可协议第 2.0 版许可。请参阅 LICENSE 以获取完整的许可文本。

除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”分发,不提供任何明示或暗示的保证或条件。请参阅许可证,了解具体管理许可证下权限和限制的语言。