thejano/easy-php-regex
Composer 安装命令:
composer require thejano/easy-php-regex
包简介
A human-readable regex builder for PHP
关键字:
README 文档
README
A Human-Readable Regex Builder for PHP
EasyRegex is a fluent and human-readable regex builder for PHP that simplifies constructing complex regular expressions without manually writing regex patterns.
Installation
To install this package using Composer, run:
composer require thejano/easy-php-regex
Usage
Creating Regex Patterns
Use the EasyRegex class to build and generate regex patterns fluently.
Example: Matching an Email Address
use TheJano\EasyRegex\EasyRegex; $regex = (new EasyRegex()) ->startAnchor() ->word() ->oneOrMore() ->add('@') ->word() ->oneOrMore() ->add('.') ->word() ->between(2, 5) ->endAnchor() ->toRegExp(); // Output: /^\w+@\w+\.\w{2,5}$/
Example: Validating a Strong Password
$regex = (new EasyRegex()) ->startAnchor() ->hasLetter() ->hasDigit() ->hasSpecialCharacter() ->atLeast(8) ->endAnchor() ->toRegExp(); // Output: /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/
Example: Matching a URL
$regex = (new EasyRegex()) ->protocol() ->www() ->word() ->oneOrMore() ->tld() ->path() ->toRegExp(); // Output: /https?:\/\/(www\.)?\w+\.[a-zA-Z]{2,}(\/\w*)*/
Available Methods
Character Classes
digit()- Matches a digit (\d)word()- Matches a word character (\w)whitespace()- Matches a whitespace character (\s)nonWhitespace()- Matches a non-whitespace character (\S)letter()- Matches a letter ([a-zA-Z])anyCharacter()- Matches any character (.)
Quantifiers
optional()- Matches zero or one times (?)exactly(int $n)- Matches exactlyntimes ({n})atLeast(int $n)- Matches at leastntimes ({n,})atMost(int $n)- Matches up tontimesbetween(int $min, int $max)- Matches betweenminandmaxtimes ({min,max})oneOrMore()- Matches one or more times (+)zeroOrMore()- Matches zero or more times (*)
Grouping & Anchors
startGroup()- Starts a non-capturing group ((?:)startCaptureGroup()- Starts a capturing group (()startNamedGroup(string $name)- Starts a named group ((?<name>)endGroup()- Ends a group ())startAnchor()- Matches the beginning of the string (^)endAnchor()- Matches the end of the string ($)
Lookaheads & Lookbehinds
negativeLookahead(string $pattern)- Negative lookahead ((?!pattern))positiveLookahead(string $pattern)- Positive lookahead ((?=pattern))positiveLookbehind(string $pattern)- Positive lookbehind ((?<=pattern))negativeLookbehind(string $pattern)- Negative lookbehind ((?<!pattern))
Flags
global()- Applies the global (g) flagcaseInsensitive()- Applies the case-insensitive (i) flagmultiline()- Applies the multiline (m) flagdotAll()- Applies the dot-all (s) flagsticky()- Applies the sticky (y) flag
Unicode Support
unicodeChar(string $variant = '')- Matches a Unicode letter (\p{L})unicodeDigit()- Matches a Unicode digit (\p{N})unicodePunctuation()- Matches a Unicode punctuation (\p{P})unicodeSymbol()- Matches a Unicode symbol (\p{S})
Special Helpers
escapeLiteral(string $text)- Escapes special charactersipv4Octet()- Matches an IPv4 octet ((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))protocol()- Matcheshttporhttpswww()- Matches optionalwww.tld()- Matches a top-level domain (\.[a-zA-Z]{2,})path()- Matches a URL path ((\/\w*)*)
Generating Regex Patterns
toString()- Returns the raw regex patterntoRegExp()- Returns the full regex pattern wrapped in/.../
Running Tests
To run the test suite using Pest, execute:
vendor/bin/pest
License
This package is open-sourced software licensed under the MIT license.
Author
Created by Pshtiwan Mahmood.
thejano/easy-php-regex 适用场景与选型建议
thejano/easy-php-regex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「builder」 「regex」 「regex-builder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 thejano/easy-php-regex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 thejano/easy-php-regex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 thejano/easy-php-regex 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Sphinx Query Builder extension for the Laravel Database package
Anax Database Active Record module for model classes.
Advanced TYPO3 redirect management for sys_redirect with regex and host/language-aware matching, CSV/.htaccess import/export, categories and priority, automatic slug redirect workflows, plus hit/log analytics.
Adds PHP's preg_replace function as a Twig filter.
Convert Regular Expressions into text, for testing
Adds request-parameter validation to the SLIM 3.x PHP framework
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-20