定制 danbettles/php-reggie 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danbettles/php-reggie

最新稳定版本:v3.0.0

Composer 安装命令:

composer require danbettles/php-reggie

包简介

Reggie is a very simple regular-expression builder

README 文档

README

Reggie is a very simple regular-expression (regex) builder for PHP. It was created to eliminate the clutter and confusion involved in assembling regexes from various different parts, to help prevent hard-to-find bugs and make code easier to understand.

Regexes can be confusing enough: having to also mentally-parse multiple complicated concatenation and interpolation operations makes things many times more difficult. That's where Reggie can help. Its fluent interface breaks things down into more distinct pieces, eliminates a ton of hieroglyphics, makes things more readable.

Examples

A few examples adapted from real-world code.

Note

For the sake of clarity and brevity, the following code uses literals as inputs. Consequently, some examples may appear simplistic—perhaps even pointless. Indeed, the benefits of using Reggie will become apparent only when regexes must be built from various variables, constants, etc.

PHP Pathnames

$regexStr = (new Builder())
    ->caseInsensitive()
    ->anchorEnd()
    ->addLiteral('.php')
    ->buildString()
;

// '~\.php$~i' === $regexStr

Project Paths to Ignore

$builder = new Builder();

$regexStr = $builder
    ->anchorStart()
    ->addLiteral("/path/to/project/")
    ->addSubpattern(
        $builder->listOfAlternatives(['vendor', 'var', 'node_modules'], quoteEach: true)
    )
    ->addLiteral('/')
    ->buildString()
;

// '~^/path/to/project/(vendor|var|node_modules)/~' === $regexStr

Usage

Builder

Generally speaking, the builder class provides two kinds of methods for building a regex:

  • methods that change the flags;
  • methods that add chunks (patterns or literals).

Important

Methods that add chunks have the prefix "add"; these must be called in the order you want the chunks to appear in the regex. Other methods can be called whenever makes sense to you.

统计信息

  • 总下载量: 46
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: ISC
  • 更新时间: 2025-11-19