[php-src] Issue #13868: `preg_match` require match
| From: | mvorisek | Date: | Tue, 02 Apr 2024 09:47:43 +0000 |
| Subject: | [php-src] Issue #13868: `preg_match` require match | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246697@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13868
Author: mvorisek
### Description
preg_match is often used to match/parse expected data. Currently, user is required to
handle no match.
This is a feature request to add flag like PREG_REQUIRE_MATCH.
The expected behaviour is the same as now when such flag is not specified or the regex was matched.
When specified and the regex was not matched, an exception like "Regular expression
"..." was not matched" will be thrown.
Such flag should be support by preg_match_all too, ie. throwing on zero matches. Other
functions like preg_replace should support this flag as well.
The motivation of this feature request is to simplify the usage (ie. to not have handle no match in
user code) and allow static analysers to rely on narrowed (non-false) result.