flexic / regex-builder
提供正则表达式的构建器。
0.0.1
2022-12-10 22:58 UTC
Requires
- php: ^8.1
Requires (Dev)
- ergebnis/php-cs-fixer-config: ^4.9.0
- phpstan/phpstan: ^1.8.8
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpstan/phpstan-strict-rules: ^1.4.4
- phpunit/phpunit: ^9.5.25
This package is auto-updated.
Last update: 2024-08-29 17:53:22 UTC
README
此包提供正则表达式的构建器。
它旨在使开发者使用正则表达式更加容易和可读。
安装
运行
composer require flexic/regex-builder
使用方法
Regex-Builder 允许您以流畅的面向对象方式构建正则表达式。
以下示例展示了如何构建正则表达式。
$pattern = new \Flexic\RegexBuilder\Pattern(); $pattern->add( new \Flexic\RegexBuilder\Expr\Group([ new \Flexic\RegexBuilder\Expr\LookAround\Ahead( new \Flexic\RegexBuilder\Expr\Enclosed( new \Flexic\RegexBuilder\Expr\Literal('<picture>'), ), ), new \Flexic\RegexBuilder\Expr\Enclosed( new \Flexic\RegexBuilder\Expr\Option([ new \Flexic\RegexBuilder\Expr\Marker\AnyWord(), new \Flexic\RegexBuilder\Expr\Marker\AnyNonWord(), ]), ), new \Flexic\RegexBuilder\Expr\LookAround\Follow( new \Flexic\RegexBuilder\Expr\Literal('</picture>'), ), ]), );
使用 Regex-Builder 构建的图案可以转换为正则表达式的字符串表示。
$pattern->toString(); // returns: '(?=(\<picture\>))(\w|\W)(?<=\<\/picture\>)'
或者用于 flexix/regex
库。
表达式词法分析
Regex-Builder 提供一个词法分析器,将正则表达式的字符串表示转换为对象表示。
🚧 词法分析器目前正在开发中,将在以后完成。
许可证
此包使用 GNU 许可证授权。
请参阅 LICENSE.md。