Introduction to T-Regx
Documentation for version: 0.41.2
T-Regx provides clean API for regular expressions, as well as solving more complicated issues with PHP regex (like eliminating false positives, validating groups) and including features utterly missing in PHP: Prepared patterns, pattern lists, built-in alteration and more, as well as removing uncertainty with false negatives and false positives.
We have multiple entry methods to create
Pattern, each with its own use case:
- Standard pattern -
- Prepared patterns - to safely use user input in patterns (see Prepared Patterns)
- Pattern lists -
Pattern::list(['\d+', '[a-z]+'])to use many patterns at once
- Literal string value -
Additionally, compatibility API remains available, which accepts delimiters
- Compatibility legacy -
PcrePattern::of('/\d+/m')to use vanilla patterns
pattern() is available as a shorthand for
Additionally, as a convenience method,
pattern() global function is just an alias for
#T-Regx prepared patterns
@ is being bound the figures passed as the second argument of
You can learn more about prepared patterns in Prepared Patterns.
#Pattern lists in T-Regx
Pattern::list() results an instance of
PatternList, which contains the list of the patterns.
PatternList exposes multiple methods which act on the list of patterns. It is preferable to call
PatternList.testAny() instead of calling
Pattern.test() in a loop, since
PatterList will use
Pattern:list() also accepts instances of
Pattern. Any T-Regx method that instantiates
can be used with
Pattern::list() is the same as passing that very same string in
adding it to the list.
PatternList cannot contain other instances of
You can learn more about
Pattern::list() in Multiple patterns.
Pattern::of() is used with a delimited pattern, then characters
"/" will simply be treated literally
Delimited patterns are still supported for completeness with flags, with
PcrePattern::of(). Both versions are equal with each other.
They are particularly useful when T-Regx is used with other libraries, which return delimited regular expressions.
Pattern is instantiated with
PcrePattern, then it behaves exactly as the input regular expression would.
There are certain fixed that T-Regx performs on the input, but they are kept to a minimal proportion.
An example of such change could be token
\c\, which works fine with
Pattern, but fails with