Re: Pre-RFC: adding a Regex\CompiledRegex class for compiling regular expressions
| From: | Sjoerd Langkemper | Date: | Fri, 25 Sep 2026 06:56:01 +0000 |
| Subject: | Re: Pre-RFC: adding a Regex\CompiledRegex class for compiling regular expressions | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132627@lists.php.net to get a copy of this message | ||
On Wed, Sep 23, 2026, at 21:01, Gina P. Banyard wrote:
> This class could lay the foundation on which to build a new nice OO API
Nice. I am in favor of improving the API, instead of slapping more flags onto the existing one.
> the pattern *must* be a UTF-8 pattern
Does this also apply to the subject? I recently had a reason to remove the u modifier from a regex:
if the input is not valid UTF8, preg_match silently fails without a match. I think I was scraping
web pages and discovered that some webpages don't contain valid UTF8, and that made it
impossible to use preg_match with UTF8 on it.
> returning a bool type
Would it make more sense to return a Match object, with captured groups?
The proposed API would result in calls like this:
new CompiledRegex(".*", false, false, false, true, true, true, false, true)
where it is hard to determine what all the true/false parameters mean. Would it be better to pass
enums instead? Or is this solved by editor hints nowadays?
Regards,
Sjoerd Langkemper