T-Regx / T Regx
Labels
Projects that are alternatives of or similar to T Regx
T-Regx | Regular Expressions library
PHP regular expressions brought up to modern standards.
See documentation at t-regx.com.
Installation
Installation for PHP 7.1 and later (PHP 8 as well):
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
-
-
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.
-
-
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.Pattern::format()
allows converting user-supplied masks into full-fledged patterns safely. -
- 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:
-
Surrounding slashes or tildes (
/pattern/
or~patttern~
) are not compulsory. -
- Malformed patterns in
preg_()
methods don't makepreg_last_error()
to return error. - Notices, warnings 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.
- Malformed patterns in
-
- Descriptive, chainable 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]]]
-
Certain arguments cause fatal errors with
preg_()
methods. T-Regx will throw a catchable exception, instead of a Fatal Error.
What's better
or
Sponsors
Andreas Leathley - developing SquirrelPHP
T-Regx is developed thanks to
License
T-Regx is MIT licensed.