Because CleanRegex is built on top of SafeRegex, we get protection against warnings, compile errors, notices, fatal errors and 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, as well as removing uncertainty with false negatives and false positives.
We have multiple entry points, each with its own use case:
- Standard functions -
- Compatibility legacy -
Pattern::pcre('/\d+/')to use vanilla patterns
- Prepared patterns - to safely use user data in patterns (see Prepared Patterns)
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.
If you use
Pattern::of() with a delimited pattern, like so:
/ characters will simply be treated literally:
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.