PHPackages                             pfinalclub/regex-center - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. pfinalclub/regex-center

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

pfinalclub/regex-center
=======================

PHP 版本的正则表达式管理库，内置 100+ 精选正则，支持团队标准化

v1.0.0(6mo ago)511MITPHPPHP &gt;=8.1

Since Oct 21Pushed 6mo agoCompare

[ Source](https://github.com/pfinalclub/pfinal-regex-center)[ Packagist](https://packagist.org/packages/pfinalclub/regex-center)[ Docs](https://github.com/pfinalclub/regex-center)[ RSS](/packages/pfinalclub-regex-center/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

PFinal Regex Center
===================

[](#pfinal-regex-center)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHP Version](https://camo.githubusercontent.com/7663c9d53dc13cedaf0660a8745a7e77d2dd711257f36aa86ebce12a0600ef42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c75652e737667)](https://php.net)[![Build Status](https://camo.githubusercontent.com/c27a457659b89ee4f1f80f7995c559dd37f2051bde7167ad25791e5c5c92cc8e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e2e737667)](https://github.com/pfinalclub/regex-center)

PHP 版本的正则表达式管理库，内置 100+ 精选正则，支持团队标准化和 PSR-4。

简介
--

[](#简介)

Regex Center = 正则 + 管理，一个专业的正则表达式管理库，让团队和项目的正则变得可管理、可维护、可复用。

核心价值
----

[](#核心价值)

- **开箱即用**：内置 100+ 精选正则，覆盖常见场景
- **团队管理**：搭建属于你的正则管理体系，统一团队标准
- **类型安全**：严格类型检查，减少运行时错误
- **高性能**：单例模式，内存占用小
- **可扩展**：支持自定义正则表达式注入
- **安全性**：内置 ReDoS 攻击防护

安装
--

[](#安装)

```
composer require pfinal/regex-center
```

使用方法
----

[](#使用方法)

### 方式一：直接使用内置正则表达式

[](#方式一直接使用内置正则表达式)

```
use pfinalclub\RegexCenter\RegexManager;

$regex = RegexManager::getInstance();

// 验证邮箱
if ($regex->test('email:basic', 'test@example.com')) {
    echo "邮箱格式正确";
}

// 验证手机号（中国）
if ($regex->test('phone:CN', '13812345678')) {
    echo "手机号格式正确";
}

// 提取文本中的所有邮箱
$text = "联系我们：admin@example.com 或 support@example.org";
$emails = $regex->extractAll('email:basic', $text);
print_r($emails);

// 替换文本中的所有URL
$text = "访问我们的网站 https://www.example.com 获取更多信息";
$newText = $regex->replaceAll('url', $text, '[链接]');
echo $newText;
```

### 方式二：团队自定义配置（推荐）

[](#方式二团队自定义配置推荐)

```
use pfinalclub\RegexCenter\RegexManager;

$regex = RegexManager::getInstance();

// 团队自定义正则配置
$customPatterns = [
    'email' => '/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/',
    'phone' => [
        'CN' => '/^1[3-9]\d{9}$/',
        'US' => '/^\+?1?-?\(?[0-9]{3}\)?-?[0-9]{3}-?[0-9]{4}$/',
        'UK' => '/^\+44[0-9]{10}$/'
    ],
    'id' => '/^[A-Za-z0-9]{8,10}$/',
    'custom' => '/^custom-pattern$/'
];

// 注入团队自定义配置（保留内置模式）
$regex->inject($customPatterns);

// 使用自定义的正则表达式
$regex->test('email', 'user@example.com');     // 使用自定义邮箱正则
$regex->test('phone:UK', '+441234567890');    // 使用自定义英国手机号正则
$regex->test('custom', 'custom-value');       // 使用自定义正则
```

```

## 内置正则表达式类型

### 邮箱验证
- `email:basic` - 基础邮箱格式
- `email:strict` - 严格邮箱格式
- `email:enterprise` - 企业邮箱格式

### 电话号码
- `phone:CN` - 中国手机号
- `phone:US` - 美国电话号码
- `phone:UK` - 英国电话号码
- `phone:JP` - 日本电话号码

### 身份证
- `idCard:CN` - 中国身份证
- `idCard:US` - 美国社会安全号

### URL 链接
- `url:basic` - 基础 URL 格式
- `url:strict` - 严格 URL 格式

### IP 地址
- `ip:v4` - IPv4 地址
- `ip:v6` - IPv6 地址

### 银行卡
- `bankCard:CN` - 中国银行卡
- `bankCard:VISA` - Visa 卡
- `bankCard:MASTERCARD` - Mastercard
- `bankCard:AMEX` - American Express

### 密码强度
- `password:strong` - 强密码（包含大小写、数字、特殊字符）
- `password:medium` - 中等密码（包含字母和数字）
- `password:weak` - 弱密码（仅长度要求）

### 其他类型
- `username` - 用户名
- `date` - 日期格式
- `time` - 时间格式
- `color` - 颜色代码
- `postalCode` - 邮政编码
- `currency` - 货币格式

## 高级用法

### 批量验证

```php
$regex = RegexManager::getInstance();

$data = [
    'email' => 'user@example.com',
    'phone' => '13812345678',
    'url' => 'https://www.example.com'
];

$rules = [
    'email' => 'email:basic',
    'phone' => 'phone:CN',
    'url' => 'url:basic'
];

foreach ($rules as $field => $pattern) {
    if (!$regex->test($pattern, $data[$field])) {
        echo "{$field} 格式不正确\n";
    }
}

```

### 文本处理

[](#文本处理)

```
$text = "联系我们：admin@example.com 或访问 https://www.example.com";

// 提取所有邮箱
$emails = $regex->extractAll('email:basic', $text);

// 高亮所有 URL
$highlighted = $regex->highlight('url:basic', $text, '$&');

// 替换敏感信息
$masked = $regex->replaceAll('email:basic', $text, '[邮箱]');
```

运行测试
----

[](#运行测试)

```
# 首先安装依赖
composer install

# 运行测试
./vendor/bin/phpunit

# 运行测试并生成覆盖率报告
composer test-coverage

# 代码质量检查
composer quality

# 代码风格修复
composer cs-fix
```

贡献指南
----

[](#贡献指南)

1. Fork 本仓库
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 打开 Pull Request

许可证
---

[](#许可证)

MIT License - 详见 [LICENSE](LICENSE) 文件

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance66

Regular maintenance activity

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

203d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/570b67182b6589731273ec44b5ae533c4f2d91f38f648b285e21ca66f41a3a45?d=identicon)[南丞](/maintainers/%E5%8D%97%E4%B8%9E)

---

Tags

phpvalidationlibraryregexregular expressionpattern

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pfinalclub-regex-center/health.svg)

```
[![Health](https://phpackages.com/badges/pfinalclub-regex-center/health.svg)](https://phpackages.com/packages/pfinalclub-regex-center)
```

###  Alternatives

[eftec/validationone

It's a php library for fetch and validate fields

113.8k4](/packages/eftec-validationone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
