Because CleanRegex is built on top of SafeRegex, we get protection against warnings/compile-errors/notices/magic-values for free!
Additionally, CleanRegex 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, offsets while replacing, in-place replacement, composite patterns, built-alteration and more.
We have multiple entry points, each with its own usecase:
- Standard functions -
- Compatibility legacy -
Pattern::pcre('/\d+/')to use vanilla patterns
- Prepared patterns - to safely use user data in patterns (see Prepared Patterns)
Class method style:
Global function style:
Notice, that these patterns are not delimited. Smart T-Regx will conveniently add them for you, if you
pattern(). You can add flags to your regular expression by passing a second argument.
To learn more, go to Automatic Delimiters.
Of course, you can still use delimited patterns with flags, with
Pattern::pcre(). Both versions are equal with each other.
To safely handle unsafe date or user input, see Prepared Patterns.