Documentation for version: 0.39.0
T-Regx is a lightweight, high-level library for regular expressions in PHP. It's designed to be suitable for simple projects and enterprise solutions.
The name "T-Regx" is a combination of words "Regex" and "T-Rex" (Tyrannosaurus Rex).
Main features of T-Regx are:
- Single-point entry
- Regular expressions without delimiters (so
- UTF-8 support out of the box
- Prepared Patterns handling unsafe characters (e.g. user input, delicate values)
- Both replacing and matching is with detailed
- Uses PHP regular expressions under the hood, but doesn't leak any of its interface or flaws
Surpasses PHP in many ways:
- Doesn't use PHP warning/error/notice/fatal system, uses only exceptions, for example
- Doesn't use any flags, default arguments or varargs, everything is done with methods
- Doesn't return
nullon error, but throws a suitable exception instead (for example
- Doesn't return
""to indicate an unmatched group, but uses
Group.matched()and other methods instead
When calling multiple methods on the same
$matcher object, T-Regx doesn't make any unnecessary calls to underlying
This example illustrates a pattern that allows us to match string enclosed in double quote
or a backtick
`, for example
`foo`, but not
"foo` and not
Additionally, we want the word to be anything we want, including data that potentially holds special regular expression values.
true if, and only if a pattern matches the given subject. In this example,
we can see that despite the dot character used in
"my.word", the subject
'content with "my!word"' isn't matched.
That's because prepared patterns (such as patterns created with
Pattern::inject()) treat each value literally,
not as regular expression special characters.
You can read more about prepared patterns in Handling user input.
Pattern is designed with methods and objects, IDE suggestions can be very helpful when developing applications
Pattern. Proper suggestions from IDE reduce time spent of reading documentations and finding the correct
syntax or notation.
T-Regx doesn't interfere with userspace in any way. After using
Matcher with pattern
or subject which can't be matched because of malformed unicode encoding, or perhaps because of
catastrophic backtracking, a suitable exception will be thrown, but the userspace will be left intact,
preg_last_error() won't return errors.
T-Regx doesn't override error handlers or exception handlers, since that could greatly pollute userspace and render the client application less reliable.