
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 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::pcre()
, Pattern::inject()
or Pattern::bind()
. 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::prepare()
, Pattern::inject()
, Pattern::bind()
, Pattern::compose()
, Pattern::format()
and Pattern::template()
.
For constant patterns use Pattern::of()
or simply pattern()
.
Functional programming
You can use either pattern()
or pattern()
, or Prepared Patterns.
T-Regx utilizes chainable, functional programming with methods like filter()
, map()
, flatMap()
, first()
/findFirst()
, etc.
Apart from standard functional methods, T-Regx provides dedicated methods, suited more for working with string
s and capturing groups from T-Regx, like map()
, mapIfExists()
, mapAndCallback()
, etc.
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.

