Wrapper for PHP regular expression, providing exceptions and error handling.
PHP regular expressions brought up to modern standards.
See documentation at t-regx.com.
Installation for PHP 7.1 and later:
composer require rawr/t-regx
You, choose the interface: - I choose to keep PHP methods (but protected from errors):
preg::match_all(),
preg::replace_callback(),
preg::split()- I choose the modern regex API:
pattern()->test(),
pattern()->match(),
pattern()->replace()
Full API documentation is available at t-regx.com. List of changes is available in ChangeLog.md.
Open T-Regx fiddle and start playing around.
:bulb: See documentation at t-regx.com
Simply swap
preg_match()to
preg::match(), and your method is safe! Arguments and return types remain the same.
Surrounding slashes or tildes (
/pattern/or
~patttern~) are not compulsory.
preg::are converted to exceptions.
preg_()can never fail, because it throws
PregExceptionon warning/error.
preg_()methods might fail, return
false/
nulland NOT trigger a warning. Separate exception,
SuspectedReturnPregExceptionis then thrown by T-Regx.
No Reflection used,
No (...varargs),
No (boolean arguments, true),
(No flags, 1),
[No [nested, [arrays]]]
Certain arguments cause fatal errors with
preg_()methods. T-Regx will throw a catchable exception, instead of a Fatal Error.
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 provides
Pattern::inject()and
Pattern::bind()methods, designed specifically for handling potentially unsafe data.
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)
or
Andreas Leathley - developing SquirrelPHP
T-Regx is MIT licensed.