The php\util\Regex class provides an immutable implementation of regular expression functionality. It allows for pattern matching, splitting strings, and performing replacements. Because the class is immutable, operations that modify the state (like region() or reset()) return a new instance or are handled via specific methods.
Key capabilities include:
- Static matching: Quick checks using
match() or split() without manual instantiation. - Instance matching: Creating a
Regex object to perform complex operations like finding all groups, replacing with callbacks, or managing search regions. - Escaping: Using
quote() and quoteReplacement() to treat strings as literal patterns or replacement text.