rawr / t-regx
The most advanced PHP regexp library. Clean, descriptive wrapper functions enhancing PCRE extension methods.
Fund package maintenance!
Danon
Installs: 16 285
Dependents: 1
Suggesters: 0
Security: 0
Stars: 256
Watchers: 8
Forks: 8
Open Issues: 4
Requires
- php: >=7.1.0
- ext-mbstring: *
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^9.0 || ^8.0 || ^7.5
- rawr/cross-data-providers: ^2.3.0
- rawr/fqn-check: ^1.2.0
README
T-Regx | Regular Expressions library
PHP regular expressions brought up to modern standards.
See documentation at t-regx.com.
- Installation
- API
- Documentation
- T-Regx fiddle - Try online
- Overview
- Supported PHP versions
- Comparison
- License
Installation
Installation for PHP 7.1 and later:
composer require rawr/t-regx
API
You, choose the interface:
-
I choose to keep PHP methods (but protected from errors):
Scroll to see -
preg::match_all()
,preg::replace_callback()
,preg::split()
-
I choose the modern regex API:
Scroll to see -
pattern()->test()
,pattern()->match()
,pattern()->replace()
Documentation
Full API documentation is available at t-regx.com. List of changes is available in ChangeLog.md.
Try it online, in your browser!
Open T-Regx fiddle and start playing around.
Why T-Regx stands out?
💡 See documentation at t-regx.com
-
No change in API!
-
You can use T-Regx safe features and exception-based error handling, without changing your API.
Simply swap
preg_match()
topreg::match()
, and your method is safe! Arguments and return types remain the same.
-
-
Working with the developer
- Errors:
- Not even touching your error handlers in any way
- Converts all PCRE notices/error/warnings to exceptions
- Preventing fatal errors
- Strings:
- Tracking offset and subjects while replacing strings
- Fixing error with multi-byte offset (utf-8 safe)
- Errors:
-
Automatic delimiters for your pattern
Surrounding slashes or tildes (
/pattern/
or~patttern~
) are not compulsory. -
Converting Warnings to Exceptions
- Warning or errors during
preg::
are converted to exceptions. preg_()
can never fail, because it throwsPregException
on warning/error.- In some cases,
preg_()
methods might fail, returnfalse
/null
and NOT trigger a warning. Separate exception,SuspectedReturnPregException
is then thrown by T-Regx.
- Warning or errors during
-
Written with clean API
- Descriptive interface
- SRP methods
- UTF-8 support out-of-the-box
No Reflection used
,No (...varargs)
,No (boolean arguments, true)
,(No flags, 1)
,[No [nested, [arrays]]]
-
Protects your from fatal errors
Certain arguments cause fatal errors with
preg_()
methods. T-Regx will throw a catchable exception, instead of a Fatal Error. -
Prepared patterns
Using user data (for example with
preg_quote()
) isn't always safe with PCRE, as well as just not being that convenient to use. T-Regx providesPattern::inject()
andPattern::bind()
methods, designed specifically for handling potentially unsafe data.
Supported PHP versions
Continuous integration builds are running for:
PHP 7.1
(7.1.0
,7.1.12
,7.1.13
,7.1.27
)PHP 7.2
(7.2.0
,7.2.15
,7.2.28
)PHP 7.3
(7.3.0
,7.3.6
,7.3.15
)PHP 7.4
(7.4.0
,7.4.3
)PHP 8.0
(nightly)
What's better
or
Sponsors
Andreas Leathley - developing SquirrelPHP
T-Regx is developed thanks to
License
T-Regx is MIT licensed.