Re: [DISCUSSION] Validating regex pattern
| From: | Tim Düsterhus | Date: | Fri, 03 Oct 2025 15:02:10 +0000 |
| Subject: | Re: [DISCUSSION] Validating regex pattern | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128771@lists.php.net to get a copy of this message | ||
Hi
Am 2025-10-02 13:03, schrieb Ayesh Karunaratne:
I completely agree with this and the previous reply from Juliette.I also fully agree with Juliette: This is something that needs to be done in ext/pcre.
AI however don't think that PREG_THROW_ON_ERROR is the best solution here. A flag that effectively *always* needs to be passed is not good API design and functions likePREG_THROW_ON_ERRORflag would be the best of both worlds: - Provides a nice safe-guard against potentially invalid regexps and surfaces them up as an exception. - Provides validation functionality with engine-provided error messages. - We do not need to keep up with the regex engines because validation is done by the engine. - Works similar to theJSON_THROW_ON_ERRORflag.
preg_replace() don't currently support flags. While it would definitely increase the scope of an RFC, I second Thomas' notion of providing a new (object-oriented) pcre API that would also allow for passing modifiers independently of the expression itself, avoiding the need for delimiters (and escaping them when dynamically constructing a regex).
Best regards
Tim Düsterhus