Comparison table of plain PHP and T-Regx

Here's a little table of some of the differences between the behaviour of plain PHP preg_*() methods and T-Regx API.
Plain PHPT-Regx
Plain PHPT-Regx
Invalid pattern(eg. /unclosed[A-/)Issues a warningMalformedPatternException with descriptive message
Corrupted subject(eg. malformed utf-8 sequence)
  • Different methods return different error values (false, null or [])
  • preg_last_error() returns error code
RuntimeCleanRegexException with descriptive message
Overly complex pattern(eg. containing ?R)
  • No warning
  • preg_last_error() returns error code
RuntimeSafeRegexException with descriptive message
Returning an invalid replacement value
  • preg_last_error() returns success code (returns PREG_NO_ERROR)
  • Silently converts the value to string (e.g. integer)
  • Raises a warning (e.g. array)
  • Throws a fatal error, terminating the application (e.g. stdClass, objects without __toString)
InvalidReplacementException with descriptive message
Using an invalid capturing group name(eg. name !@#$, index -2)Actually tries to get the groupInvalidArgumentException with descriptive message
Using a nonexistent group(group name typo, group deleted)Actually tries to get the groupNonexistentGroupException with descriptive message
Using an un-matched group(conditional group, unmatched by subject)Actually tries to get the groupGroupNotMatchedException with descriptive message
Offsets in UTF-8(eg. 18€)In bytes5 bytes
  • Method offset()
    • 3 characters
  • Method byteOffset()
    • 5 bytes
Worst case complexity(string|int|null)[][][]

array of arrays of arrays of string/null and integer - preg_match_all() with PREG_OFFSET_CAPTURE

string[]array of strings