T-Regx (T-Rex and RegExp) is a lightweight, high-level Regular Expressions library.
Its main features are:
Cleaning the mess after PHP regular expressions API:
- All false positives and false negatives are eliminated
- Special values like
''aren't used to indicate errors.
- Unifying differences between matching, replacing, splitting - all operations
- Results aren't a dull
stringarray, but a dedicated
- Based on exceptions - No warnings, errors or fatal errors or notices.
- Relieving developers from brain strain:
Being explicit and descriptive - (why is explicit interface so important?):
- Each function obeys SRP
- Functionalities are represented with methods (and not flags or default arguments)
- No default parameters
- No flags
- No var-args
Why is explicit interface so important?
T-Regx' aim is to relieve programmers from brain strain while reading and writing code. Our mission is to make developers write/read a line and immediately go on, without thinking about what it does or what side effects it may cause.
While reading this code...
preg_match($pattern, $subject, $match);
...developers must stop for a moment and think:
- Will this match the first occurrence? Or all of them?
- Will the
$subjectmatch the pattern
- Will this trigger a warning, if I mess up my regexp?
- Will this return
falseor raise a warning, on error?
- Will this return
'', if the
- Will this return my value? Or my value nested in arrays?
What should be obvious, is now complicated and causes many questions and assumptions for the reader.
While using T-Regx, some things are certain. For example:
$result = pattern($pattern)->match($subject)->first();
$result must contain the first occurrence. It must contain your value.
It will never contain
false or an empty array.
MalformedPatternException would be thrown, if
is malformed. It would also throw
SubjectNotMatchedException if the
$pattern doesn't match the
first() does return
'', it's only because it supposed to do that; that is "when a pattern matched
a string of length 0".
It also never raises any warnings or fatal errors.