
T-Regx
Programmer-oriented Regular Expressions wrapper library for PHP
- Lightweight
- Reliable
- Secure
- Based on exceptions
Quiz about Vanilla-PHP regular expressions
Super easy, see for yourself how well you know Vanilla-PHP regular expressions. Maybe it turns out you don't need T-Regx, after all :)
Start quizSafeRegex converts warnings to exceptions
SafeRegex watches for warnings, analyzes preg_()
methods return values and looks up preg_last_error()
to validate a call. If it fails, an exception is thrown.
Match your subject against a pattern
Use pattern()->test()
to check whether your subject matches a given regular expression.
In this case whether ^[a-zA-Z][a-zA-Z0-9]{1,15}$
matches $username
.
Match details
With pattern()->match()
and pattern()->replace()
, it's trivial to retrieve, iterate, map and filter matches with callbacks and a detailed Detail
.
It doesn't matter whether the pattern was constructed with Pattern::of()
, pattern()
, Pattern::inject()
or Pattern::template()
. The Detail
is always the same.
Checkout the documentation about Detail
, which describes every Detail
method.
Uniform API for matching and replacing
pattern()->match()
and pattern()->replace()
callbacks receive the same interface Detail
.
Detail
used for matching and replacing has exactly the same methods and returns the same values for given $pattern
and $subject
.
You can also try it online in 10 seconds - there are examples in the as sandbox for your own tries.
Prepared patterns
With Prepared Patterns you can safely build your regular expressions, without worrying about it becoming malformed or dangerous.
T-Regx provides a wide variety of prepared patterns, for different needs: Pattern::inject()
, Pattern::list()
, Pattern::mask()
and Pattern::template()
.
For constant patterns use Pattern::of()
or simply pattern()
.
Different ways of instantiating Patterns
Regardless of whether you build your pattern using Pattern::of()
, pattern()
helper, or maybe using prepared patterns like Pattern::inject()
/Pattern::alternate()
, the interface of Pattern
is the same.
Additionally, building patterns using Pattern::mask()
or Pattern::template()
also share the same Pattern
interface.
Try T-Regx online
Before you install, you can try T-Regx online, right in your browser.
You can use repl.it using your GitHub account, Facebook account or Google account -T-Regx on repl.it
Written with clean design in mind
T-Regx utilises well designed interfaces, so your IDE will aid you as you type! We follow real SOLID and OOP.

