okapi/wildcards

PHP Wildcards 是一个将通配符转换为正则表达式的 PHP 库。

1.0.1 2023-06-05 15:32 UTC

This package is auto-updated.

Last update: 2024-09-05 18:15:52 UTC


README

PHP Wildcards

License: MIT Twitter: @WalterWoshid PHP: >=8.0 Packagist Build

Coverage - PHP 8.0 Coverage - PHP 8.1 Coverage - PHP 8.2

PHP Wildcards 是一个将通配符转换为正则表达式的 PHP 库。

安装

composer require okapi/wildcards

用法

<?php

use Okapi\Wildcards\Regex;

// Simple wildcard
$regex = Regex::fromWildcard('*.php');
$regex->matches('index.php'); // true
$regex->matches('index.html'); // false

// Wildcard with groups
$regex = Regex::fromWildcard('(*.php)|(*.html)');
$regex->matches('index.php'); // true
$regex->matches('index.html'); // true
$regex->matches('index.js'); // false

// Wildcard with optional characters
$regex = Regex::fromWildcard('index[*].php');
$regex->matches('index.php'); // true
$regex->matches('index.test.php'); // true
$regex->matches('index_2.php'); // true

支持的通配符

  • * = 任意数量的字符
  • ? = 任意单个字符
  • [ ] = 可选字符
  • ( ) = 组
  • | = 或

测试

  • 运行 composer run-script test
  • 运行 composer run-script test-coverage

显示您的支持

如果此项目对您有帮助,请给一个 ⭐!

📝 许可证

版权 © 2023 Valentin Wotschel.
此项目采用 MIT 许可证。